Skip to content

Commit

Permalink
Pass VolumeAttributesClass Parameters as MutableParameters to CreateV…
Browse files Browse the repository at this point in the history
…olume

Signed-off-by: Connor Catlett <[email protected]>
  • Loading branch information
ConnorJC3 committed Nov 16, 2023
1 parent 35faf00 commit a9d5c82
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 39 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
CMDS=csi-provisioner
all: build

# TODO: Change in csi-release-tools before PR merge?
export CSI_PROW_GO_VERSION_BUILD=1.21
include release-tools/build.make
include doc/doc.make
41 changes: 39 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ type ProvisionerCSITranslator interface {

// requiredCapabilities provides a set of extra capabilities required for special/optional features provided by a plugin
type requiredCapabilities struct {
snapshot bool
clone bool
snapshot bool
clone bool
modifyVolume bool
}

// NodeDeployment contains additional parameters for running external-provisioner alongside a
Expand Down Expand Up @@ -440,6 +441,13 @@ func (p *csiProvisioner) checkDriverCapabilities(rc *requiredCapabilities) error
return fmt.Errorf("CSI driver does not support clone operations: controller CLONE_VOLUME capability is not reported")
}
}
if rc.modifyVolume {
// Check whether plugin supports modifying volumes
// If not, PVCs with an associated VolumeAttributesClass cannot be created
if !p.controllerCapabilities[csi.ControllerServiceCapability_RPC_MODIFY_VOLUME] {
return fmt.Errorf("CSI driver does not support VolumeAttributesClass: controller MODIFY_VOLUME capability is not reported")
}
}

return nil
}
Expand Down Expand Up @@ -596,6 +604,17 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
}
}

var vacName string
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
if claim.Spec.VolumeAttributesClassName != nil {
vacName = *claim.Spec.VolumeAttributesClassName
}
}

if vacName != "" {
rc.modifyVolume = true
}

if err := p.checkDriverCapabilities(rc); err != nil {
return nil, controller.ProvisioningFinished, err
}
Expand Down Expand Up @@ -742,6 +761,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
deletionAnnSecrets.namespace = provisionerSecretRef.Namespace
}

if vacName != "" {
vac, err := p.client.StorageV1alpha1().VolumeAttributesClasses().Get(ctx, vacName, metav1.GetOptions{})
if err != nil {
return nil, controller.ProvisioningNoChange, err
}

if vac.DriverName != p.driverName {
return nil, controller.ProvisioningFinished, fmt.Errorf("VAC %s referenced in PVC is for driver %s which does not match driver name %s", vacName, vac.DriverName, p.driverName)
}

req.MutableParameters = vac.Parameters
}

return &prepareProvisionResult{
fsType: fsType,
migratedVolume: migratedVolume,
Expand Down Expand Up @@ -920,6 +952,11 @@ func (p *csiProvisioner) Provision(ctx context.Context, options controller.Provi
pv.Spec.PersistentVolumeSource.CSI.FSType = result.fsType
}

vacName := claim.Spec.VolumeAttributesClassName
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) && vacName != nil && *vacName != "" {
pv.Spec.VolumeAttributesClassName = vacName
}

klog.V(2).Infof("successfully created PV %v for PVC %v and csi volume name %v", pv.Name, options.PVC.Name, pv.Spec.CSI.VolumeHandle)

if result.migratedVolume {
Expand Down
Loading

0 comments on commit a9d5c82

Please sign in to comment.