mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Fix race conditions
This commit is contained in:
		@@ -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
 | 
				
			||||||
@@ -271,18 +272,20 @@ func TestUpdatePod(t *testing.T) {
 | 
				
			|||||||
			expectDelete: false,
 | 
								expectDelete: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			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)},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectDelete: true,
 | 
								expectDelete: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			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)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user