Wire contexts to Core controllers
This commit is contained in:
@@ -56,10 +56,10 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
0)
|
||||
|
||||
// Start informer and controllers
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
informers.Start(stopCh)
|
||||
go epController.Run(1, stopCh)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
informers.Start(ctx.Done())
|
||||
go epController.Run(ctx, 1)
|
||||
|
||||
// Create namespace
|
||||
ns := framework.CreateTestingNamespace("test-endpoints-updates", server, t)
|
||||
@@ -83,7 +83,7 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
createdPod, err := client.CoreV1().Pods(ns.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := client.CoreV1().Pods(ns.Name).Create(ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create pod %s: %v", pod.Name, err)
|
||||
}
|
||||
@@ -93,14 +93,14 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
Phase: v1.PodRunning,
|
||||
PodIPs: []v1.PodIP{{IP: "1.1.1.1"}, {IP: "2001:db8::"}},
|
||||
}
|
||||
_, err = client.CoreV1().Pods(ns.Name).UpdateStatus(context.TODO(), createdPod, metav1.UpdateOptions{})
|
||||
_, err = client.CoreV1().Pods(ns.Name).UpdateStatus(ctx, createdPod, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update status of pod %s: %v", pod.Name, err)
|
||||
}
|
||||
|
||||
// Create a service associated to the pod
|
||||
svc := newService(ns.Name, "foo1")
|
||||
svc1, err := client.CoreV1().Services(ns.Name).Create(context.TODO(), svc, metav1.CreateOptions{})
|
||||
svc1, err := client.CoreV1().Services(ns.Name).Create(ctx, svc, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create service %s: %v", svc.Name, err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
// Obtain ResourceVersion of the new endpoint created
|
||||
var resVersion string
|
||||
if err := wait.PollImmediate(1*time.Second, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(context.TODO(), svc.Name, metav1.GetOptions{})
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(ctx, svc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Logf("error fetching endpoints: %v", err)
|
||||
return false, nil
|
||||
@@ -121,7 +121,7 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
|
||||
// Force recomputation on the endpoint controller
|
||||
svc1.SetAnnotations(map[string]string{"foo": "bar"})
|
||||
_, err = client.CoreV1().Services(ns.Name).Update(context.TODO(), svc1, metav1.UpdateOptions{})
|
||||
_, err = client.CoreV1().Services(ns.Name).Update(ctx, svc1, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update service %s: %v", svc1.Name, err)
|
||||
}
|
||||
@@ -131,13 +131,13 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
// was recomputed before asserting, since we only have 1 worker
|
||||
// in the endpoint controller
|
||||
svc2 := newService(ns.Name, "foo2")
|
||||
_, err = client.CoreV1().Services(ns.Name).Create(context.TODO(), svc2, metav1.CreateOptions{})
|
||||
_, err = client.CoreV1().Services(ns.Name).Create(ctx, svc2, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create service %s: %v", svc.Name, err)
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(1*time.Second, wait.ForeverTestTimeout, func() (bool, error) {
|
||||
_, err := client.CoreV1().Endpoints(ns.Name).Get(context.TODO(), svc2.Name, metav1.GetOptions{})
|
||||
_, err := client.CoreV1().Endpoints(ns.Name).Get(ctx, svc2.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Logf("error fetching endpoints: %v", err)
|
||||
return false, nil
|
||||
@@ -149,7 +149,7 @@ func TestEndpointUpdates(t *testing.T) {
|
||||
|
||||
// the endpoint controller should not update the endpoint created for the original
|
||||
// service since nothing has changed, the resource version has to be the same
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(context.TODO(), svc.Name, metav1.GetOptions{})
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(ctx, svc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("error fetching endpoints: %v", err)
|
||||
}
|
||||
@@ -185,10 +185,10 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
0)
|
||||
|
||||
// Start informer and controllers
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
informers.Start(stopCh)
|
||||
go epController.Run(1, stopCh)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
informers.Start(ctx.Done())
|
||||
go epController.Run(ctx, 1)
|
||||
|
||||
// Create namespace
|
||||
ns := framework.CreateTestingNamespace("test-endpoints-terminating", server, t)
|
||||
@@ -232,13 +232,13 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
createdPod, err := client.CoreV1().Pods(ns.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
createdPod, err := client.CoreV1().Pods(ns.Name).Create(ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create pod %s: %v", pod.Name, err)
|
||||
}
|
||||
|
||||
createdPod.Status = pod.Status
|
||||
_, err = client.CoreV1().Pods(ns.Name).UpdateStatus(context.TODO(), createdPod, metav1.UpdateOptions{})
|
||||
_, err = client.CoreV1().Pods(ns.Name).UpdateStatus(ctx, createdPod, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to update status of pod %s: %v", pod.Name, err)
|
||||
}
|
||||
@@ -261,14 +261,14 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = client.CoreV1().Services(ns.Name).Create(context.TODO(), svc, metav1.CreateOptions{})
|
||||
_, err = client.CoreV1().Services(ns.Name).Create(ctx, svc, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create service %s: %v", svc.Name, err)
|
||||
}
|
||||
|
||||
// poll until associated Endpoints to the previously created Service exists
|
||||
if err := wait.PollImmediate(1*time.Second, 10*time.Second, func() (bool, error) {
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(context.TODO(), svc.Name, metav1.GetOptions{})
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(ctx, svc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
@@ -287,7 +287,7 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
t.Fatalf("endpoints not found: %v", err)
|
||||
}
|
||||
|
||||
err = client.CoreV1().Pods(ns.Name).Delete(context.TODO(), pod.Name, metav1.DeleteOptions{})
|
||||
err = client.CoreV1().Pods(ns.Name).Delete(ctx, pod.Name, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("error deleting test pod: %v", err)
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
if err := wait.PollImmediate(1*time.Second, 10*time.Second, func() (bool, error) {
|
||||
// Ensure that the recently deleted Pod exists but with a deletion timestamp. If the Pod does not exist,
|
||||
// we should fail the test since it is no longer validating against a terminating pod.
|
||||
pod, err := client.CoreV1().Pods(ns.Name).Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
pod, err := client.CoreV1().Pods(ns.Name).Get(ctx, pod.Name, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return false, fmt.Errorf("expected Pod %q to exist with deletion timestamp but was not found: %v", pod.Name, err)
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func TestEndpointWithTerminatingPod(t *testing.T) {
|
||||
return false, errors.New("pod did not have deletion timestamp set")
|
||||
}
|
||||
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(context.TODO(), svc.Name, metav1.GetOptions{})
|
||||
endpoints, err := client.CoreV1().Endpoints(ns.Name).Get(ctx, svc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user