From 41adcc5496f86b5ad30dd7aa628c1602fb0df728 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Tue, 17 May 2016 14:55:30 +0200 Subject: [PATCH] Speed up binding of provisioned volumes This fixes e2e test for provisioning - it expects that provisioned volumes are bound quickly. Majority of this patch is update of test framework needs to initialize the controller appropriately. --- .../persistentvolume_controller.go | 17 +++++++++++++++-- .../persistentvolume_controller_test.go | 3 +-- .../persistentvolume_framework_test.go | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pkg/controller/persistentvolume/persistentvolume_controller.go b/pkg/controller/persistentvolume/persistentvolume_controller.go index 956feced3c0..87c3018aa0f 100644 --- a/pkg/controller/persistentvolume/persistentvolume_controller.go +++ b/pkg/controller/persistentvolume/persistentvolume_controller.go @@ -651,8 +651,6 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume) } return nil } else if claim.Spec.VolumeName == "" { - // This block collapses into a NOP; we're leaving this here for - // completeness. if hasAnnotation(volume.ObjectMeta, annBoundByController) { // The binding is not completed; let PVC sync handle it glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume not bound yet, waiting for syncClaim to fix it", volume.Name) @@ -660,6 +658,21 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume) // Dangling PV; try to re-establish the link in the PVC sync glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume was bound and got unbound (by user?), waiting for syncClaim to fix it", volume.Name) } + // In both cases, the volume is Bound and the claim is Pending. + // Next syncClaim will fix it. To speed it up, we enqueue the claim + // into the controller, which results in syncClaim to be called + // shortly (and in the right goroutine). + // This speeds up binding of provisioned volumes - provisioner saves + // only the new PV and it expects that next syncClaim will bind the + // claim to it. + clone, err := conversion.NewCloner().DeepCopy(claim) + if err != nil { + return fmt.Errorf("error cloning claim %q: %v", claimToClaimKey(claim), err) + } + err = ctrl.claimController.Requeue(clone) + if err != nil { + return fmt.Errorf("error enqueing claim %q for faster sync: %v", claimToClaimKey(claim), err) + } return nil } else if claim.Spec.VolumeName == volume.Name { // Volume is bound to a claim properly, update status if necessary diff --git a/pkg/controller/persistentvolume/persistentvolume_controller_test.go b/pkg/controller/persistentvolume/persistentvolume_controller_test.go index 552874f331f..9ae9010340f 100644 --- a/pkg/controller/persistentvolume/persistentvolume_controller_test.go +++ b/pkg/controller/persistentvolume/persistentvolume_controller_test.go @@ -128,8 +128,7 @@ func TestControllerSync(t *testing.T) { client := &fake.Clientset{} volumeSource := framework.NewFakeControllerSource() claimSource := framework.NewFakeControllerSource() - ctrl := newPersistentVolumeController(client) - ctrl.initializeController(time.Minute, volumeSource, claimSource) + ctrl := newPersistentVolumeController(client, volumeSource, claimSource) reactor := newVolumeReactor(client, ctrl, volumeSource, claimSource, test.errors) for _, claim := range test.initialClaims { claimSource.Add(claim) diff --git a/pkg/controller/persistentvolume/persistentvolume_framework_test.go b/pkg/controller/persistentvolume/persistentvolume_framework_test.go index b1f798d0f09..f18578c5f3e 100644 --- a/pkg/controller/persistentvolume/persistentvolume_framework_test.go +++ b/pkg/controller/persistentvolume/persistentvolume_framework_test.go @@ -484,7 +484,7 @@ func newVolumeReactor(client *fake.Clientset, ctrl *PersistentVolumeController, return reactor } -func newPersistentVolumeController(kubeClient clientset.Interface) *PersistentVolumeController { +func newPersistentVolumeController(kubeClient clientset.Interface, volumeSource, claimSource cache.ListerWatcher) *PersistentVolumeController { ctrl := &PersistentVolumeController{ volumes: newPersistentVolumeOrderedIndex(), claims: cache.NewStore(cache.MetaNamespaceKeyFunc), @@ -496,6 +496,15 @@ func newPersistentVolumeController(kubeClient clientset.Interface) *PersistentVo createProvisionedPVRetryCount: createProvisionedPVRetryCount, createProvisionedPVInterval: 5 * time.Millisecond, } + + // Create dummy volume/claim sources for controller watchers when needed + if volumeSource == nil { + volumeSource = framework.NewFakeControllerSource() + } + if claimSource == nil { + claimSource = framework.NewFakeControllerSource() + } + ctrl.initializeController(5*time.Second, volumeSource, claimSource) return ctrl } @@ -723,7 +732,7 @@ func runSyncTests(t *testing.T, tests []controllerTest) { // Initialize the controller client := &fake.Clientset{} - ctrl := newPersistentVolumeController(client) + ctrl := newPersistentVolumeController(client, nil, nil) reactor := newVolumeReactor(client, ctrl, nil, nil, test.errors) for _, claim := range test.initialClaims { ctrl.claims.Add(claim) @@ -767,7 +776,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest) { // Initialize the controller client := &fake.Clientset{} - ctrl := newPersistentVolumeController(client) + ctrl := newPersistentVolumeController(client, nil, nil) reactor := newVolumeReactor(client, ctrl, nil, nil, test.errors) for _, claim := range test.initialClaims { ctrl.claims.Add(claim)