Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bertinatto committed Aug 31, 2021
1 parent 7736e72 commit ce12293
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ const (

snapshotNotBound = "snapshot %s not bound"

pvcCloneFinalizer = "provisioner.storage.kubernetes.io/cloning-protection"
pvcCloneFinalizer = "provisioner.storage.kubernetes.io/cloning-protection"
pvcProvisioningFinalizer = "provisioner.storage.kubernetes.io/provisioning-protection"
)

var (
Expand Down Expand Up @@ -619,6 +620,11 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
req.VolumeContentSource = volumeContentSource
}

err = p.setFinalizer(ctx, claim, pvcProvisioningFinalizer)
if err != nil {
return nil, controller.ProvisioningNoChange, err
}

if claim.Spec.DataSource != nil && rc.clone {
err = p.setCloneFinalizer(ctx, claim)
if err != nil {
Expand Down Expand Up @@ -893,6 +899,21 @@ func (p *csiProvisioner) setCloneFinalizer(ctx context.Context, pvc *v1.Persiste
return nil
}

func (p *csiProvisioner) setFinalizer(ctx context.Context, pvc *v1.PersistentVolumeClaim, finalizer string) error {
claim, err := p.claimLister.PersistentVolumeClaims(pvc.Namespace).Get(pvc.Name)
if err != nil {
return err
}

if !checkFinalizer(claim, finalizer) {
claim.Finalizers = append(claim.Finalizers, finalizer)
_, err := p.client.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(ctx, claim, metav1.UpdateOptions{})
return err
}

return nil
}

func (p *csiProvisioner) supportsTopology() bool {
return SupportsTopology(p.pluginCapabilities)
}
Expand Down

0 comments on commit ce12293

Please sign in to comment.