deployment controller: use contextual logging
This commit is contained in:
@@ -34,6 +34,8 @@ import (
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/authentication/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/authorization/install"
|
||||
@@ -181,10 +183,10 @@ func newFixture(t testing.TB) *fixture {
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fixture) newController() (*DeploymentController, informers.SharedInformerFactory, error) {
|
||||
func (f *fixture) newController(ctx context.Context) (*DeploymentController, informers.SharedInformerFactory, error) {
|
||||
f.client = fake.NewSimpleClientset(f.objects...)
|
||||
informers := informers.NewSharedInformerFactory(f.client, controller.NoResyncPeriodFunc())
|
||||
c, err := NewDeploymentController(informers.Apps().V1().Deployments(), informers.Apps().V1().ReplicaSets(), informers.Core().V1().Pods(), f.client)
|
||||
c, err := NewDeploymentController(ctx, informers.Apps().V1().Deployments(), informers.Apps().V1().ReplicaSets(), informers.Core().V1().Pods(), f.client)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -204,16 +206,16 @@ func (f *fixture) newController() (*DeploymentController, informers.SharedInform
|
||||
return c, informers, nil
|
||||
}
|
||||
|
||||
func (f *fixture) runExpectError(deploymentName string, startInformers bool) {
|
||||
f.run_(deploymentName, startInformers, true)
|
||||
func (f *fixture) runExpectError(ctx context.Context, deploymentName string, startInformers bool) {
|
||||
f.run_(ctx, deploymentName, startInformers, true)
|
||||
}
|
||||
|
||||
func (f *fixture) run(deploymentName string) {
|
||||
f.run_(deploymentName, true, false)
|
||||
func (f *fixture) run(ctx context.Context, deploymentName string) {
|
||||
f.run_(ctx, deploymentName, true, false)
|
||||
}
|
||||
|
||||
func (f *fixture) run_(deploymentName string, startInformers bool, expectError bool) {
|
||||
c, informers, err := f.newController()
|
||||
func (f *fixture) run_(ctx context.Context, deploymentName string, startInformers bool, expectError bool) {
|
||||
c, informers, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
f.t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -223,7 +225,7 @@ func (f *fixture) run_(deploymentName string, startInformers bool, expectError b
|
||||
informers.Start(stopCh)
|
||||
}
|
||||
|
||||
err = c.syncDeployment(context.TODO(), deploymentName)
|
||||
err = c.syncDeployment(ctx, deploymentName)
|
||||
if !expectError && err != nil {
|
||||
f.t.Errorf("error syncing deployment: %v", err)
|
||||
} else if expectError && err == nil {
|
||||
@@ -268,6 +270,8 @@ func filterInformerActions(actions []core.Action) []core.Action {
|
||||
}
|
||||
|
||||
func TestSyncDeploymentCreatesReplicaSet(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -280,10 +284,12 @@ func TestSyncDeploymentCreatesReplicaSet(t *testing.T) {
|
||||
f.expectUpdateDeploymentStatusAction(d)
|
||||
f.expectUpdateDeploymentStatusAction(d)
|
||||
|
||||
f.run(testutil.GetKey(d, t))
|
||||
f.run(ctx, testutil.GetKey(d, t))
|
||||
}
|
||||
|
||||
func TestSyncDeploymentDontDoAnythingDuringDeletion(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -293,10 +299,12 @@ func TestSyncDeploymentDontDoAnythingDuringDeletion(t *testing.T) {
|
||||
f.objects = append(f.objects, d)
|
||||
|
||||
f.expectUpdateDeploymentStatusAction(d)
|
||||
f.run(testutil.GetKey(d, t))
|
||||
f.run(ctx, testutil.GetKey(d, t))
|
||||
}
|
||||
|
||||
func TestSyncDeploymentDeletionRace(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -318,11 +326,15 @@ func TestSyncDeploymentDeletionRace(t *testing.T) {
|
||||
f.expectGetDeploymentAction(d)
|
||||
// Sync should fail and requeue to let cache catch up.
|
||||
// Don't start informers, since we don't want cache to catch up for this test.
|
||||
f.runExpectError(testutil.GetKey(d, t), false)
|
||||
f.runExpectError(ctx, testutil.GetKey(d, t), false)
|
||||
}
|
||||
|
||||
// issue: https://github.com/kubernetes/kubernetes/issues/23218
|
||||
func TestDontSyncDeploymentsWithEmptyPodSelector(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -332,10 +344,12 @@ func TestDontSyncDeploymentsWithEmptyPodSelector(t *testing.T) {
|
||||
|
||||
// Normally there should be a status update to sync observedGeneration but the fake
|
||||
// deployment has no generation set so there is no action happening here.
|
||||
f.run(testutil.GetKey(d, t))
|
||||
f.run(ctx, testutil.GetKey(d, t))
|
||||
}
|
||||
|
||||
func TestReentrantRollback(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -359,13 +373,15 @@ func TestReentrantRollback(t *testing.T) {
|
||||
// Rollback is done here
|
||||
f.expectUpdateDeploymentAction(d)
|
||||
// Expect no update on replica sets though
|
||||
f.run(testutil.GetKey(d, t))
|
||||
f.run(ctx, testutil.GetKey(d, t))
|
||||
}
|
||||
|
||||
// TestPodDeletionEnqueuesRecreateDeployment ensures that the deletion of a pod
|
||||
// will requeue a Recreate deployment iff there is no other pod returned from the
|
||||
// client.
|
||||
func TestPodDeletionEnqueuesRecreateDeployment(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
foo := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -377,7 +393,7 @@ func TestPodDeletionEnqueuesRecreateDeployment(t *testing.T) {
|
||||
f.rsLister = append(f.rsLister, rs)
|
||||
f.objects = append(f.objects, foo, rs)
|
||||
|
||||
c, _, err := f.newController()
|
||||
c, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -388,7 +404,7 @@ func TestPodDeletionEnqueuesRecreateDeployment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
c.deletePod(pod)
|
||||
c.deletePod(logger, pod)
|
||||
|
||||
if !enqueued {
|
||||
t.Errorf("expected deployment %q to be queued after pod deletion", foo.Name)
|
||||
@@ -399,6 +415,8 @@ func TestPodDeletionEnqueuesRecreateDeployment(t *testing.T) {
|
||||
// will not requeue a Recreate deployment iff there are other pods returned from the
|
||||
// client.
|
||||
func TestPodDeletionDoesntEnqueueRecreateDeployment(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
foo := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -413,7 +431,7 @@ func TestPodDeletionDoesntEnqueueRecreateDeployment(t *testing.T) {
|
||||
// return a non-empty list.
|
||||
f.podLister = append(f.podLister, pod1, pod2)
|
||||
|
||||
c, _, err := f.newController()
|
||||
c, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -424,7 +442,7 @@ func TestPodDeletionDoesntEnqueueRecreateDeployment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
c.deletePod(pod1)
|
||||
c.deletePod(logger, pod1)
|
||||
|
||||
if enqueued {
|
||||
t.Errorf("expected deployment %q not to be queued after pod deletion", foo.Name)
|
||||
@@ -436,6 +454,8 @@ func TestPodDeletionDoesntEnqueueRecreateDeployment(t *testing.T) {
|
||||
// pod returned from the client in the case where a deployment has multiple replica
|
||||
// sets, some of which have empty owner references.
|
||||
func TestPodDeletionPartialReplicaSetOwnershipEnqueueRecreateDeployment(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
foo := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -449,7 +469,7 @@ func TestPodDeletionPartialReplicaSetOwnershipEnqueueRecreateDeployment(t *testi
|
||||
f.rsLister = append(f.rsLister, rs1, rs2)
|
||||
f.objects = append(f.objects, foo, rs1, rs2)
|
||||
|
||||
c, _, err := f.newController()
|
||||
c, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -460,7 +480,7 @@ func TestPodDeletionPartialReplicaSetOwnershipEnqueueRecreateDeployment(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
c.deletePod(pod)
|
||||
c.deletePod(logger, pod)
|
||||
|
||||
if !enqueued {
|
||||
t.Errorf("expected deployment %q to be queued after pod deletion", foo.Name)
|
||||
@@ -472,6 +492,8 @@ func TestPodDeletionPartialReplicaSetOwnershipEnqueueRecreateDeployment(t *testi
|
||||
// returned from the client in the case where a deployment has multiple replica sets,
|
||||
// some of which have empty owner references.
|
||||
func TestPodDeletionPartialReplicaSetOwnershipDoesntEnqueueRecreateDeployment(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
foo := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -488,7 +510,7 @@ func TestPodDeletionPartialReplicaSetOwnershipDoesntEnqueueRecreateDeployment(t
|
||||
// return a non-empty list.
|
||||
f.podLister = append(f.podLister, pod)
|
||||
|
||||
c, _, err := f.newController()
|
||||
c, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -499,7 +521,7 @@ func TestPodDeletionPartialReplicaSetOwnershipDoesntEnqueueRecreateDeployment(t
|
||||
}
|
||||
}
|
||||
|
||||
c.deletePod(pod)
|
||||
c.deletePod(logger, pod)
|
||||
|
||||
if enqueued {
|
||||
t.Errorf("expected deployment %q not to be queued after pod deletion", foo.Name)
|
||||
@@ -507,6 +529,8 @@ func TestPodDeletionPartialReplicaSetOwnershipDoesntEnqueueRecreateDeployment(t
|
||||
}
|
||||
|
||||
func TestGetReplicaSetsForDeployment(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
// Two Deployments with same labels.
|
||||
@@ -523,7 +547,7 @@ func TestGetReplicaSetsForDeployment(t *testing.T) {
|
||||
f.objects = append(f.objects, d1, d2, rs1, rs2)
|
||||
|
||||
// Start the fixture.
|
||||
c, informers, err := f.newController()
|
||||
c, informers, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -531,7 +555,7 @@ func TestGetReplicaSetsForDeployment(t *testing.T) {
|
||||
defer close(stopCh)
|
||||
informers.Start(stopCh)
|
||||
|
||||
rsList, err := c.getReplicaSetsForDeployment(context.TODO(), d1)
|
||||
rsList, err := c.getReplicaSetsForDeployment(ctx, d1)
|
||||
if err != nil {
|
||||
t.Fatalf("getReplicaSetsForDeployment() error: %v", err)
|
||||
}
|
||||
@@ -543,7 +567,7 @@ func TestGetReplicaSetsForDeployment(t *testing.T) {
|
||||
t.Errorf("getReplicaSetsForDeployment() = %v, want [%v]", rsNames, rs1.Name)
|
||||
}
|
||||
|
||||
rsList, err = c.getReplicaSetsForDeployment(context.TODO(), d2)
|
||||
rsList, err = c.getReplicaSetsForDeployment(ctx, d2)
|
||||
if err != nil {
|
||||
t.Fatalf("getReplicaSetsForDeployment() error: %v", err)
|
||||
}
|
||||
@@ -557,6 +581,8 @@ func TestGetReplicaSetsForDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetReplicaSetsForDeploymentAdoptRelease(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -573,7 +599,7 @@ func TestGetReplicaSetsForDeploymentAdoptRelease(t *testing.T) {
|
||||
f.objects = append(f.objects, d, rsAdopt, rsRelease)
|
||||
|
||||
// Start the fixture.
|
||||
c, informers, err := f.newController()
|
||||
c, informers, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -581,7 +607,7 @@ func TestGetReplicaSetsForDeploymentAdoptRelease(t *testing.T) {
|
||||
defer close(stopCh)
|
||||
informers.Start(stopCh)
|
||||
|
||||
rsList, err := c.getReplicaSetsForDeployment(context.TODO(), d)
|
||||
rsList, err := c.getReplicaSetsForDeployment(ctx, d)
|
||||
if err != nil {
|
||||
t.Fatalf("getReplicaSetsForDeployment() error: %v", err)
|
||||
}
|
||||
@@ -595,6 +621,8 @@ func TestGetReplicaSetsForDeploymentAdoptRelease(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPodMapForReplicaSets(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -620,7 +648,7 @@ func TestGetPodMapForReplicaSets(t *testing.T) {
|
||||
f.objects = append(f.objects, d, rs1, rs2, pod1, pod2, pod3, pod4)
|
||||
|
||||
// Start the fixture.
|
||||
c, informers, err := f.newController()
|
||||
c, informers, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -661,6 +689,8 @@ func TestGetPodMapForReplicaSets(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddReplicaSet(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -676,12 +706,12 @@ func TestAddReplicaSet(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
|
||||
dc.addReplicaSet(rs1)
|
||||
dc.addReplicaSet(klog.FromContext(ctx), rs1)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -694,7 +724,7 @@ func TestAddReplicaSet(t *testing.T) {
|
||||
t.Errorf("queue.Get() = %v, want %v", got, want)
|
||||
}
|
||||
|
||||
dc.addReplicaSet(rs2)
|
||||
dc.addReplicaSet(logger, rs2)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -709,6 +739,8 @@ func TestAddReplicaSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddReplicaSetOrphan(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
// 2 will match the RS, 1 won't.
|
||||
@@ -726,18 +758,20 @@ func TestAddReplicaSetOrphan(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
|
||||
dc.addReplicaSet(rs)
|
||||
dc.addReplicaSet(logger, rs)
|
||||
if got, want := dc.queue.Len(), 2; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateReplicaSet(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -754,7 +788,7 @@ func TestUpdateReplicaSet(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -762,7 +796,7 @@ func TestUpdateReplicaSet(t *testing.T) {
|
||||
prev := *rs1
|
||||
next := *rs1
|
||||
bumpResourceVersion(&next)
|
||||
dc.updateReplicaSet(&prev, &next)
|
||||
dc.updateReplicaSet(logger, &prev, &next)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -778,7 +812,7 @@ func TestUpdateReplicaSet(t *testing.T) {
|
||||
prev = *rs2
|
||||
next = *rs2
|
||||
bumpResourceVersion(&next)
|
||||
dc.updateReplicaSet(&prev, &next)
|
||||
dc.updateReplicaSet(logger, &prev, &next)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -793,6 +827,8 @@ func TestUpdateReplicaSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateReplicaSetOrphanWithNewLabels(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -808,7 +844,7 @@ func TestUpdateReplicaSetOrphanWithNewLabels(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -818,13 +854,15 @@ func TestUpdateReplicaSetOrphanWithNewLabels(t *testing.T) {
|
||||
prev.Labels = map[string]string{"foo": "notbar"}
|
||||
next := *rs
|
||||
bumpResourceVersion(&next)
|
||||
dc.updateReplicaSet(&prev, &next)
|
||||
dc.updateReplicaSet(logger, &prev, &next)
|
||||
if got, want := dc.queue.Len(), 2; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateReplicaSetChangeControllerRef(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -838,7 +876,7 @@ func TestUpdateReplicaSetChangeControllerRef(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -848,13 +886,15 @@ func TestUpdateReplicaSetChangeControllerRef(t *testing.T) {
|
||||
prev.OwnerReferences = []metav1.OwnerReference{*metav1.NewControllerRef(d2, controllerKind)}
|
||||
next := *rs
|
||||
bumpResourceVersion(&next)
|
||||
dc.updateReplicaSet(&prev, &next)
|
||||
dc.updateReplicaSet(logger, &prev, &next)
|
||||
if got, want := dc.queue.Len(), 2; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateReplicaSetRelease(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -868,7 +908,7 @@ func TestUpdateReplicaSetRelease(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
@@ -878,13 +918,15 @@ func TestUpdateReplicaSetRelease(t *testing.T) {
|
||||
next := *rs
|
||||
next.OwnerReferences = nil
|
||||
bumpResourceVersion(&next)
|
||||
dc.updateReplicaSet(&prev, &next)
|
||||
dc.updateReplicaSet(logger, &prev, &next)
|
||||
if got, want := dc.queue.Len(), 2; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteReplicaSet(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -901,12 +943,12 @@ func TestDeleteReplicaSet(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
|
||||
dc.deleteReplicaSet(rs1)
|
||||
dc.deleteReplicaSet(logger, rs1)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -919,7 +961,7 @@ func TestDeleteReplicaSet(t *testing.T) {
|
||||
t.Errorf("queue.Get() = %v, want %v", got, want)
|
||||
}
|
||||
|
||||
dc.deleteReplicaSet(rs2)
|
||||
dc.deleteReplicaSet(logger, rs2)
|
||||
if got, want := dc.queue.Len(), 1; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
@@ -934,6 +976,8 @@ func TestDeleteReplicaSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteReplicaSetOrphan(t *testing.T) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
d1 := newDeployment("d1", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -949,18 +993,20 @@ func TestDeleteReplicaSetOrphan(t *testing.T) {
|
||||
|
||||
// Create the fixture but don't start it,
|
||||
// so nothing happens in the background.
|
||||
dc, _, err := f.newController()
|
||||
dc, _, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
|
||||
dc.deleteReplicaSet(rs)
|
||||
dc.deleteReplicaSet(logger, rs)
|
||||
if got, want := dc.queue.Len(), 0; got != want {
|
||||
t.Fatalf("queue.Len() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGetPodMapForDeployment(b *testing.B) {
|
||||
_, ctx := ktesting.NewTestContext(b)
|
||||
|
||||
f := newFixture(b)
|
||||
|
||||
d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
|
||||
@@ -984,7 +1030,7 @@ func BenchmarkGetPodMapForDeployment(b *testing.B) {
|
||||
f.objects = append(f.objects, objects...)
|
||||
|
||||
// Start the fixture.
|
||||
c, informers, err := f.newController()
|
||||
c, informers, err := f.newController(ctx)
|
||||
if err != nil {
|
||||
b.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user