mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 00:31:00 +00:00
Fix strict linting
Signed-off-by: Kante Yin <kerthcet@gmail.com>
This commit is contained in:
parent
a7035f5459
commit
859359ad6a
@ -36,7 +36,9 @@ func TestExportRejection(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
clientSet.CoreV1().Namespaces().Delete(ctx, "export-fail", metav1.DeleteOptions{})
|
||||
if err := clientSet.CoreV1().Namespaces().Delete(ctx, "export-fail", metav1.DeleteOptions{}); err != nil {
|
||||
t.Errorf("error whiling deleting the namespace, err: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
result := clientSet.Discovery().RESTClient().Get().AbsPath("/api/v1/namespaces/export-fail").Param("export", "true").Do(ctx)
|
||||
|
@ -49,7 +49,7 @@ const (
|
||||
timeout = time.Second * 10
|
||||
)
|
||||
|
||||
func setup(t testing.TB, maxReadonlyRequestsInFlight, MaxMutatingRequestsInFlight int) (context.Context, *rest.Config, framework.TearDownFunc) {
|
||||
func setup(t testing.TB, maxReadonlyRequestsInFlight, maxMutatingRequestsInFlight int) (context.Context, *rest.Config, framework.TearDownFunc) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
@ -58,7 +58,7 @@ func setup(t testing.TB, maxReadonlyRequestsInFlight, MaxMutatingRequestsInFligh
|
||||
// Ensure all clients are allowed to send requests.
|
||||
opts.Authorization.Modes = []string{"AlwaysAllow"}
|
||||
opts.GenericServerRunOptions.MaxRequestsInFlight = maxReadonlyRequestsInFlight
|
||||
opts.GenericServerRunOptions.MaxMutatingRequestsInFlight = MaxMutatingRequestsInFlight
|
||||
opts.GenericServerRunOptions.MaxMutatingRequestsInFlight = maxMutatingRequestsInFlight
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -321,7 +320,7 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
})
|
||||
}
|
||||
nodes = append(nodes, node)
|
||||
if _, err := cs.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().Nodes().Create(testCtx.Ctx, node, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("Failed to create node: %q, err: %v", klog.KObj(node), err)
|
||||
}
|
||||
}
|
||||
@ -333,7 +332,7 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
test.pod.Spec.Tolerations[0].TolerationSeconds = &test.tolerationSeconds
|
||||
}
|
||||
|
||||
test.pod, err = cs.CoreV1().Pods(testCtx.NS.Name).Create(context.TODO(), test.pod, metav1.CreateOptions{})
|
||||
test.pod, err = cs.CoreV1().Pods(testCtx.NS.Name).Create(testCtx.Ctx, test.pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Test Failed: error: %q, while creating pod %q", err, klog.KObj(test.pod))
|
||||
}
|
||||
@ -345,7 +344,7 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
|
||||
if test.pod != nil {
|
||||
err = wait.PollImmediate(time.Second, time.Second*15, func() (bool, error) {
|
||||
pod, err := cs.CoreV1().Pods(test.pod.Namespace).Get(context.TODO(), test.pod.Name, metav1.GetOptions{})
|
||||
pod, err := cs.CoreV1().Pods(test.pod.Namespace).Get(testCtx.Ctx, test.pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -360,10 +359,10 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
pod, _ := cs.CoreV1().Pods(testCtx.NS.Name).Get(context.TODO(), test.pod.Name, metav1.GetOptions{})
|
||||
pod, _ := cs.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, test.pod.Name, metav1.GetOptions{})
|
||||
t.Fatalf("Error: %v, Expected test pod to be %s but it's %v", err, test.expectedWaitForPodCondition, pod)
|
||||
}
|
||||
testutils.CleanupPods(cs, t, []*v1.Pod{test.pod})
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, []*v1.Pod{test.pod})
|
||||
}
|
||||
testutils.CleanupNodes(cs, t)
|
||||
})
|
||||
|
@ -54,7 +54,7 @@ func TestDefaultBinder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create pod: %v", err)
|
||||
}
|
||||
defer testutil.CleanupPods(testCtx.ClientSet, t, []*corev1.Pod{pod})
|
||||
defer testutil.CleanupPods(testCtx.Ctx, testCtx.ClientSet, t, []*corev1.Pod{pod})
|
||||
|
||||
podCopy := pod.DeepCopy()
|
||||
if tc.anotherUID {
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
st "k8s.io/kubernetes/pkg/scheduler/testing"
|
||||
testutils "k8s.io/kubernetes/test/integration/util"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
"k8s.io/kubernetes/test/utils/ktesting"
|
||||
"k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
@ -821,11 +822,13 @@ func TestInterPodAffinity(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
for _, pod := range test.pods {
|
||||
if pod.Namespace == "" {
|
||||
pod.Namespace = defaultNS
|
||||
}
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod: %v", err)
|
||||
}
|
||||
@ -838,7 +841,7 @@ func TestInterPodAffinity(t *testing.T) {
|
||||
test.pod.Namespace = defaultNS
|
||||
}
|
||||
|
||||
testPod, err := cs.CoreV1().Pods(test.pod.Namespace).Create(context.TODO(), test.pod, metav1.CreateOptions{})
|
||||
testPod, err := cs.CoreV1().Pods(test.pod.Namespace).Create(ctx, test.pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
if !(test.errorType == "invalidPod" && apierrors.IsInvalid(err)) {
|
||||
t.Fatalf("Error while creating pod: %v", err)
|
||||
@ -854,20 +857,22 @@ func TestInterPodAffinity(t *testing.T) {
|
||||
t.Errorf("Error while trying to fit a pod: %v", err)
|
||||
}
|
||||
|
||||
err = cs.CoreV1().Pods(test.pod.Namespace).Delete(context.TODO(), test.pod.Name, *metav1.NewDeleteOptions(0))
|
||||
err = cs.CoreV1().Pods(test.pod.Namespace).Delete(ctx, test.pod.Name, *metav1.NewDeleteOptions(0))
|
||||
if err != nil {
|
||||
t.Errorf("Error while deleting pod: %v", err)
|
||||
}
|
||||
err = wait.Poll(pollInterval, wait.ForeverTestTimeout, testutils.PodDeleted(cs, testCtx.NS.Name, test.pod.Name))
|
||||
err = wait.PollUntilContextTimeout(ctx, pollInterval, wait.ForeverTestTimeout, true,
|
||||
testutils.PodDeleted(ctx, cs, testCtx.NS.Name, test.pod.Name))
|
||||
if err != nil {
|
||||
t.Errorf("Error while waiting for pod to get deleted: %v", err)
|
||||
}
|
||||
for _, pod := range test.pods {
|
||||
err = cs.CoreV1().Pods(pod.Namespace).Delete(context.TODO(), pod.Name, *metav1.NewDeleteOptions(0))
|
||||
err = cs.CoreV1().Pods(pod.Namespace).Delete(ctx, pod.Name, *metav1.NewDeleteOptions(0))
|
||||
if err != nil {
|
||||
t.Errorf("Error while deleting pod: %v", err)
|
||||
}
|
||||
err = wait.Poll(pollInterval, wait.ForeverTestTimeout, testutils.PodDeleted(cs, pod.Namespace, pod.Name))
|
||||
err = wait.PollUntilContextTimeout(ctx, pollInterval, wait.ForeverTestTimeout, true,
|
||||
testutils.PodDeleted(ctx, cs, pod.Namespace, pod.Name))
|
||||
if err != nil {
|
||||
t.Errorf("Error while waiting for pod to get deleted: %v", err)
|
||||
}
|
||||
@ -1007,7 +1012,7 @@ func TestInterPodAffinityWithNamespaceSelector(t *testing.T) {
|
||||
}
|
||||
defaultNS := "ns1"
|
||||
|
||||
createdPod, err := cs.CoreV1().Pods(test.existingPod.Namespace).Create(context.TODO(), test.existingPod, metav1.CreateOptions{})
|
||||
createdPod, err := cs.CoreV1().Pods(test.existingPod.Namespace).Create(testCtx.Ctx, test.existingPod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod: %v", err)
|
||||
}
|
||||
@ -1020,7 +1025,7 @@ func TestInterPodAffinityWithNamespaceSelector(t *testing.T) {
|
||||
test.pod.Namespace = defaultNS
|
||||
}
|
||||
|
||||
testPod, err := cs.CoreV1().Pods(test.pod.Namespace).Create(context.TODO(), test.pod, metav1.CreateOptions{})
|
||||
testPod, err := cs.CoreV1().Pods(test.pod.Namespace).Create(testCtx.Ctx, test.pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
if !(test.errorType == "invalidPod" && apierrors.IsInvalid(err)) {
|
||||
t.Fatalf("Error while creating pod: %v", err)
|
||||
@ -1035,20 +1040,21 @@ func TestInterPodAffinityWithNamespaceSelector(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error while trying to fit a pod: %v", err)
|
||||
}
|
||||
|
||||
err = cs.CoreV1().Pods(test.pod.Namespace).Delete(context.TODO(), test.pod.Name, *metav1.NewDeleteOptions(0))
|
||||
err = cs.CoreV1().Pods(test.pod.Namespace).Delete(testCtx.Ctx, test.pod.Name, *metav1.NewDeleteOptions(0))
|
||||
if err != nil {
|
||||
t.Errorf("Error while deleting pod: %v", err)
|
||||
}
|
||||
err = wait.Poll(pollInterval, wait.ForeverTestTimeout, testutils.PodDeleted(cs, testCtx.NS.Name, test.pod.Name))
|
||||
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, true,
|
||||
testutils.PodDeleted(testCtx.Ctx, cs, testCtx.NS.Name, test.pod.Name))
|
||||
if err != nil {
|
||||
t.Errorf("Error while waiting for pod to get deleted: %v", err)
|
||||
}
|
||||
err = cs.CoreV1().Pods(test.existingPod.Namespace).Delete(context.TODO(), test.existingPod.Name, *metav1.NewDeleteOptions(0))
|
||||
err = cs.CoreV1().Pods(test.existingPod.Namespace).Delete(testCtx.Ctx, test.existingPod.Name, *metav1.NewDeleteOptions(0))
|
||||
if err != nil {
|
||||
t.Errorf("Error while deleting pod: %v", err)
|
||||
}
|
||||
err = wait.Poll(pollInterval, wait.ForeverTestTimeout, testutils.PodDeleted(cs, test.existingPod.Namespace, test.existingPod.Name))
|
||||
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, true,
|
||||
testutils.PodDeleted(testCtx.Ctx, cs, test.existingPod.Namespace, test.existingPod.Name))
|
||||
if err != nil {
|
||||
t.Errorf("Error while waiting for pod to get deleted: %v", err)
|
||||
}
|
||||
@ -1504,10 +1510,10 @@ func TestPodTopologySpreadFilter(t *testing.T) {
|
||||
tt.incomingPod.SetNamespace(ns)
|
||||
|
||||
allPods := append(tt.existingPods, tt.incomingPod)
|
||||
defer testutils.CleanupPods(cs, t, allPods)
|
||||
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
|
||||
|
||||
for _, pod := range tt.existingPods {
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod during test: %v", err)
|
||||
}
|
||||
@ -1516,7 +1522,7 @@ func TestPodTopologySpreadFilter(t *testing.T) {
|
||||
t.Errorf("Error while waiting for pod during test: %v", err)
|
||||
}
|
||||
}
|
||||
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(context.TODO(), tt.incomingPod, metav1.CreateOptions{})
|
||||
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
|
||||
if err != nil && !apierrors.IsInvalid(err) {
|
||||
t.Fatalf("Error while creating pod during test: %v", err)
|
||||
}
|
||||
|
@ -2445,8 +2445,9 @@ func initTestSchedulerForFrameworkTest(t *testing.T, testCtx *testutils.TestCont
|
||||
}
|
||||
// Wait for all pods to be deleted, or will failed to create same name pods
|
||||
// required in other test cases.
|
||||
if err := wait.Poll(time.Millisecond, wait.ForeverTestTimeout,
|
||||
testutils.PodsCleanedUp(testCtx.SchedulerCtx, testCtx.ClientSet, testCtx.NS.Name)); err != nil {
|
||||
err = wait.PollUntilContextTimeout(testCtx.SchedulerCtx, time.Millisecond, wait.ForeverTestTimeout, true,
|
||||
testutils.PodsCleanedUp(testCtx.SchedulerCtx, testCtx.ClientSet, testCtx.NS.Name))
|
||||
if err != nil {
|
||||
t.Errorf("error while waiting for all pods to be deleted: %v", err)
|
||||
}
|
||||
// Kill the scheduler.
|
||||
|
@ -490,7 +490,7 @@ func TestPreemption(t *testing.T) {
|
||||
|
||||
// Cleanup
|
||||
pods = append(pods, preemptor)
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -546,7 +546,7 @@ func TestNonPreemption(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer testutils.CleanupPods(cs, t, []*v1.Pod{preemptor, victim})
|
||||
defer testutils.CleanupPods(testCtx.Ctx, cs, t, []*v1.Pod{preemptor, victim})
|
||||
preemptor.Spec.PreemptionPolicy = test.PreemptionPolicy
|
||||
victimPod, err := createPausePod(cs, victim)
|
||||
if err != nil {
|
||||
@ -647,7 +647,7 @@ func TestDisablePreemption(t *testing.T) {
|
||||
|
||||
// Cleanup
|
||||
pods = append(pods, preemptor)
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -750,7 +750,7 @@ func TestPodPriorityResolution(t *testing.T) {
|
||||
})
|
||||
})
|
||||
}
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
testutils.CleanupNodes(cs, t)
|
||||
}
|
||||
|
||||
@ -864,7 +864,7 @@ func TestPreemptionStarvation(t *testing.T) {
|
||||
allPods := pendingPods
|
||||
allPods = append(allPods, runningPods...)
|
||||
allPods = append(allPods, preemptor)
|
||||
testutils.CleanupPods(cs, t, allPods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -960,7 +960,7 @@ func TestPreemptionRaces(t *testing.T) {
|
||||
|
||||
klog.Info("Check unschedulable pods still exists and were never scheduled...")
|
||||
for _, p := range additionalPods {
|
||||
pod, err := cs.CoreV1().Pods(p.Namespace).Get(context.TODO(), p.Name, metav1.GetOptions{})
|
||||
pod, err := cs.CoreV1().Pods(p.Namespace).Get(testCtx.Ctx, p.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Error in getting Pod %v/%v info: %v", p.Namespace, p.Name, err)
|
||||
}
|
||||
@ -977,7 +977,7 @@ func TestPreemptionRaces(t *testing.T) {
|
||||
allPods := additionalPods
|
||||
allPods = append(allPods, initialPods...)
|
||||
allPods = append(allPods, preemptor)
|
||||
testutils.CleanupPods(cs, t, allPods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1461,9 +1461,13 @@ func TestPDBInPreemption(t *testing.T) {
|
||||
|
||||
// Cleanup
|
||||
pods = append(pods, preemptor)
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
cs.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
|
||||
cs.CoreV1().Nodes().DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
if err := cs.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).DeleteCollection(testCtx.Ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
|
||||
t.Errorf("error while deleting PDBs, error: %v", err)
|
||||
}
|
||||
if err := cs.CoreV1().Nodes().DeleteCollection(testCtx.Ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
|
||||
t.Errorf("error whiling deleting nodes, error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1907,7 +1911,7 @@ func TestReadWriteOncePodPreemption(t *testing.T) {
|
||||
|
||||
pods := make([]*v1.Pod, len(test.existingPods))
|
||||
t.Cleanup(func() {
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
if err := test.cleanup(); err != nil {
|
||||
t.Errorf("Error cleaning up test: %v", err)
|
||||
}
|
||||
|
@ -505,9 +505,13 @@ func TestSchedulerInformers(t *testing.T) {
|
||||
|
||||
// Cleanup
|
||||
pods = append(pods, unschedulable)
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
cs.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
|
||||
cs.CoreV1().Nodes().DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
if err := cs.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).DeleteCollection(testCtx.Ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
|
||||
t.Errorf("error whiling deleting PDBs, error: %v", err)
|
||||
}
|
||||
if err := cs.CoreV1().Nodes().DeleteCollection(testCtx.Ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
|
||||
t.Errorf("error whiling deleting nodes, error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package scoring
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -614,9 +613,9 @@ func TestPodTopologySpreadScoring(t *testing.T) {
|
||||
tt.incomingPod.SetNamespace(ns)
|
||||
|
||||
allPods := append(tt.existingPods, tt.incomingPod)
|
||||
defer testutils.CleanupPods(cs, t, allPods)
|
||||
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
|
||||
for _, pod := range tt.existingPods {
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Test Failed: error while creating pod during test: %v", err)
|
||||
}
|
||||
@ -626,7 +625,7 @@ func TestPodTopologySpreadScoring(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(context.TODO(), tt.incomingPod, metav1.CreateOptions{})
|
||||
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
|
||||
if err != nil && !apierrors.IsInvalid(err) {
|
||||
t.Fatalf("Test Failed: error while creating pod during test: %v", err)
|
||||
}
|
||||
|
@ -524,11 +524,11 @@ func TestTaintNodeByCondition(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := cs.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().Nodes().Create(testCtx.Ctx, node, metav1.CreateOptions{}); err != nil {
|
||||
t.Errorf("Failed to create node, err: %v", err)
|
||||
}
|
||||
if err := testutils.WaitForNodeTaints(cs, node, test.expectedTaints); err != nil {
|
||||
node, err = cs.CoreV1().Nodes().Get(context.TODO(), node.Name, metav1.GetOptions{})
|
||||
node, err = cs.CoreV1().Nodes().Get(testCtx.Ctx, node.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Failed to get node <%s>", node.Name)
|
||||
}
|
||||
@ -542,7 +542,7 @@ func TestTaintNodeByCondition(t *testing.T) {
|
||||
pod.Name = fmt.Sprintf("%s-%d", pod.Name, i)
|
||||
pod.Spec.Tolerations = p.tolerations
|
||||
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create pod %s/%s, error: %v",
|
||||
pod.Namespace, pod.Name, err)
|
||||
@ -563,7 +563,7 @@ func TestTaintNodeByCondition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
testutils.CleanupPods(cs, t, pods)
|
||||
testutils.CleanupPods(testCtx.Ctx, cs, t, pods)
|
||||
testutils.CleanupNodes(cs, t)
|
||||
testutils.WaitForSchedulerCacheCleanup(testCtx.Scheduler, t)
|
||||
})
|
||||
|
@ -171,9 +171,9 @@ func CleanupNodes(cs clientset.Interface, t *testing.T) {
|
||||
}
|
||||
|
||||
// PodDeleted returns true if a pod is not found in the given namespace.
|
||||
func PodDeleted(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
pod, err := c.CoreV1().Pods(podNamespace).Get(context.TODO(), podName, metav1.GetOptions{})
|
||||
func PodDeleted(ctx context.Context, c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc {
|
||||
return func(context.Context) (bool, error) {
|
||||
pod, err := c.CoreV1().Pods(podNamespace).Get(ctx, podName, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return true, nil
|
||||
}
|
||||
@ -185,8 +185,8 @@ func PodDeleted(c clientset.Interface, podNamespace, podName string) wait.Condit
|
||||
}
|
||||
|
||||
// PodsCleanedUp returns true if all pods are deleted in the specific namespace.
|
||||
func PodsCleanedUp(ctx context.Context, c clientset.Interface, namespace string) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
func PodsCleanedUp(ctx context.Context, c clientset.Interface, namespace string) wait.ConditionWithContextFunc {
|
||||
return func(context.Context) (bool, error) {
|
||||
list, err := c.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -210,7 +210,9 @@ func SyncSchedulerInformerFactory(testCtx *TestContext) {
|
||||
// CleanupTest cleans related resources which were created during integration test
|
||||
func CleanupTest(t *testing.T, testCtx *TestContext) {
|
||||
// Cleanup nodes and namespaces.
|
||||
testCtx.ClientSet.CoreV1().Nodes().DeleteCollection(testCtx.Ctx, *metav1.NewDeleteOptions(0), metav1.ListOptions{})
|
||||
if err := testCtx.ClientSet.CoreV1().Nodes().DeleteCollection(testCtx.Ctx, *metav1.NewDeleteOptions(0), metav1.ListOptions{}); err != nil {
|
||||
t.Errorf("error while cleaning up nodes, error: %v", err)
|
||||
}
|
||||
framework.DeleteNamespaceOrDie(testCtx.ClientSet, testCtx.NS, t)
|
||||
// Terminate the scheduler and apiserver.
|
||||
testCtx.CloseFn()
|
||||
@ -233,16 +235,16 @@ func RemovePodFinalizers(cs clientset.Interface, t *testing.T, pods []*v1.Pod) {
|
||||
}
|
||||
|
||||
// CleanupPods deletes the given pods and waits for them to be actually deleted.
|
||||
func CleanupPods(cs clientset.Interface, t *testing.T, pods []*v1.Pod) {
|
||||
func CleanupPods(ctx context.Context, cs clientset.Interface, t *testing.T, pods []*v1.Pod) {
|
||||
for _, p := range pods {
|
||||
err := cs.CoreV1().Pods(p.Namespace).Delete(context.TODO(), p.Name, *metav1.NewDeleteOptions(0))
|
||||
err := cs.CoreV1().Pods(p.Namespace).Delete(ctx, p.Name, *metav1.NewDeleteOptions(0))
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
t.Errorf("error while deleting pod %v/%v: %v", p.Namespace, p.Name, err)
|
||||
}
|
||||
}
|
||||
for _, p := range pods {
|
||||
if err := wait.Poll(time.Millisecond, wait.ForeverTestTimeout,
|
||||
PodDeleted(cs, p.Namespace, p.Name)); err != nil {
|
||||
if err := wait.PollUntilContextTimeout(ctx, time.Duration(time.Microsecond.Seconds()), wait.ForeverTestTimeout, true,
|
||||
PodDeleted(ctx, cs, p.Namespace, p.Name)); err != nil {
|
||||
t.Errorf("error while waiting for pod %v/%v to get deleted: %v", p.Namespace, p.Name, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user