mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
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.
This commit is contained in:
parent
c6f05c8056
commit
41adcc5496
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user