Skip to content

Commit e96ca3a

Browse files
[local] Add annotations defined params to volume creation request
1 parent 5ca5e26 commit e96ca3a

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

pkg/controller/controller.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,15 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
614614
}
615615
}
616616

617-
if vacName != "" {
617+
// Get mutable parameters from claim annotations
618+
mutableParameters := make(map[string]string)
619+
for k, v := range claim.Annotations {
620+
if param, ok := strings.CutPrefix(k, p.driverName+"/"); ok {
621+
mutableParameters[param] = v
622+
}
623+
}
624+
625+
if vacName != "" || len(mutableParameters) > 0 {
618626
rc.modifyVolume = true
619627
}
620628

@@ -665,6 +673,7 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
665673
CapacityRange: &csi.CapacityRange{
666674
RequiredBytes: int64(volSizeBytes),
667675
},
676+
MutableParameters: mutableParameters,
668677
}
669678

670679
if dataSource != nil && (rc.clone || rc.snapshot) {
@@ -769,6 +778,7 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
769778
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)
770779
}
771780

781+
// Override any mutable parameters set through annotation on the claim
772782
req.MutableParameters = vac.Parameters
773783
}
774784

pkg/controller/controller_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ func createFakePVCWithVAC(requestBytes int64, vacName string) *v1.PersistentVolu
564564
return claim
565565
}
566566

567+
// createFakePVCWithVAC returns PVC with Annotations
568+
func createFakePVCWithAnnotations(requestBytes int64, annotations map[string]string) *v1.PersistentVolumeClaim {
569+
claim := createFakeNamedPVC(requestBytes, "fake-pvc", annotations)
570+
return claim
571+
}
572+
567573
// fakeClaim returns a valid PVC with the requested settings
568574
func fakeClaim(name, namespace, claimUID string, capacity int64, boundToVolume string, phase v1.PersistentVolumeClaimPhase, class *string, mode string) *v1.PersistentVolumeClaim {
569575
claim := v1.PersistentVolumeClaim{
@@ -2376,6 +2382,45 @@ func provisionTestcases() (int64, map[string]provisioningTestcase) {
23762382
},
23772383
expectState: controller.ProvisioningFinished,
23782384
},
2385+
"normal provision with custom params in annotations": {
2386+
pluginCapabilities: provisionWithVACCapabilities,
2387+
expectCreateVolDo: func(t *testing.T, ctx context.Context, req *csi.CreateVolumeRequest) {
2388+
if !reflect.DeepEqual(req.MutableParameters, map[string]string{"iops": "10000"}) {
2389+
t.Errorf("Missing or incorrect mutable parameters")
2390+
}
2391+
},
2392+
volOpts: controller.ProvisionOptions{
2393+
StorageClass: &storagev1.StorageClass{
2394+
ReclaimPolicy: &deletePolicy,
2395+
Parameters: map[string]string{
2396+
"fstype": "ext3",
2397+
"test-param": "from-sc",
2398+
},
2399+
},
2400+
PVName: "test-name",
2401+
PVC: createFakePVCWithAnnotations(requestedBytes, map[string]string{driverName + "/iops": "10000"}),
2402+
},
2403+
expectedPVSpec: &pvSpec{
2404+
Name: "test-testi",
2405+
Annotations: map[string]string{
2406+
annDeletionProvisionerSecretRefName: "",
2407+
annDeletionProvisionerSecretRefNamespace: "",
2408+
},
2409+
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
2410+
Capacity: v1.ResourceList{
2411+
v1.ResourceName(v1.ResourceStorage): bytesToQuantity(requestedBytes),
2412+
},
2413+
CSIPVS: &v1.CSIPersistentVolumeSource{
2414+
Driver: "test-driver",
2415+
VolumeHandle: "test-volume-id",
2416+
FSType: "ext3",
2417+
VolumeAttributes: map[string]string{
2418+
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
2419+
},
2420+
},
2421+
},
2422+
expectState: controller.ProvisioningFinished,
2423+
},
23792424
"normal provision with VolumeAttributesClass but feature gate is disabled": {
23802425
featureGates: map[featuregate.Feature]bool{
23812426
features.VolumeAttributesClass: false,

0 commit comments

Comments
 (0)