mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Fix race conditions
This commit is contained in:
parent
3b5c3acd61
commit
a910ca563b
@ -40,7 +40,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var timeForControllerToProgress = 500 * time.Millisecond
|
var timeForControllerToProgressForSanityCheck = 20 * time.Millisecond
|
||||||
|
|
||||||
func getPodsAssignedToNode(ctx context.Context, c *fake.Clientset) GetPodsByNodeNameFunc {
|
func getPodsAssignedToNode(ctx context.Context, c *fake.Clientset) GetPodsByNodeNameFunc {
|
||||||
return func(nodeName string) ([]*v1.Pod, error) {
|
return func(nodeName string) ([]*v1.Pod, error) {
|
||||||
@ -228,13 +228,14 @@ func TestDeletePod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller.PodUpdated(testutil.NewPod("pod1", "node1"), nil)
|
controller.PodUpdated(testutil.NewPod("pod1", "node1"), nil)
|
||||||
// wait a bit to see if nothing will panic
|
// wait a bit to see if nothing will panic
|
||||||
time.Sleep(timeForControllerToProgress)
|
time.Sleep(timeForControllerToProgressForSanityCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePod(t *testing.T) {
|
func TestUpdatePod(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
prevPod *v1.Pod
|
prevPod *v1.Pod
|
||||||
|
awaitForScheduledEviction bool
|
||||||
newPod *v1.Pod
|
newPod *v1.Pod
|
||||||
taintedNodes map[string][]v1.Taint
|
taintedNodes map[string][]v1.Taint
|
||||||
expectPatch bool
|
expectPatch bool
|
||||||
@ -274,6 +275,7 @@ func TestUpdatePod(t *testing.T) {
|
|||||||
description: "removing toleration",
|
description: "removing toleration",
|
||||||
prevPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 100),
|
prevPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 100),
|
||||||
newPod: testutil.NewPod("pod1", "node1"),
|
newPod: testutil.NewPod("pod1", "node1"),
|
||||||
|
awaitForScheduledEviction: true,
|
||||||
taintedNodes: map[string][]v1.Taint{
|
taintedNodes: map[string][]v1.Taint{
|
||||||
"node1": {createNoExecuteTaint(1)},
|
"node1": {createNoExecuteTaint(1)},
|
||||||
},
|
},
|
||||||
@ -283,6 +285,7 @@ func TestUpdatePod(t *testing.T) {
|
|||||||
description: "lengthening toleration shouldn't work",
|
description: "lengthening toleration shouldn't work",
|
||||||
prevPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 1),
|
prevPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 1),
|
||||||
newPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 100),
|
newPod: addToleration(testutil.NewPod("pod1", "node1"), 1, 100),
|
||||||
|
awaitForScheduledEviction: true,
|
||||||
taintedNodes: map[string][]v1.Taint{
|
taintedNodes: map[string][]v1.Taint{
|
||||||
"node1": {createNoExecuteTaint(1)},
|
"node1": {createNoExecuteTaint(1)},
|
||||||
},
|
},
|
||||||
@ -303,7 +306,16 @@ func TestUpdatePod(t *testing.T) {
|
|||||||
podIndexer.Add(item.prevPod)
|
podIndexer.Add(item.prevPod)
|
||||||
controller.PodUpdated(nil, item.prevPod)
|
controller.PodUpdated(nil, item.prevPod)
|
||||||
|
|
||||||
time.Sleep(timeForControllerToProgress)
|
if item.awaitForScheduledEviction {
|
||||||
|
nsName := types.NamespacedName{Namespace: item.prevPod.Namespace, Name: item.prevPod.Name}
|
||||||
|
err := wait.PollImmediate(time.Millisecond*10, time.Second, func() (bool, error) {
|
||||||
|
scheduledEviction := controller.taintEvictionQueue.GetWorkerUnsafe(nsName.String())
|
||||||
|
return scheduledEviction != nil, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to await for scheduled eviction: %q", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
podIndexer.Update(item.newPod)
|
podIndexer.Update(item.newPod)
|
||||||
controller.PodUpdated(item.prevPod, item.newPod)
|
controller.PodUpdated(item.prevPod, item.newPod)
|
||||||
@ -841,7 +853,7 @@ func TestEventualConsistency(t *testing.T) {
|
|||||||
podIndexer.Update(item.newPod)
|
podIndexer.Update(item.newPod)
|
||||||
controller.PodUpdated(item.prevPod, item.newPod)
|
controller.PodUpdated(item.prevPod, item.newPod)
|
||||||
// wait a bit
|
// wait a bit
|
||||||
time.Sleep(timeForControllerToProgress)
|
time.Sleep(timeForControllerToProgressForSanityCheck)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user