Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass PVC annotations to req.Parameters when --extra-create-metadata is enabled #800

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"os"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -113,9 +114,10 @@ const (
nodePublishSecretNamespaceKey = "csiNodePublishSecretNamespace"

// PV and PVC metadata, used for sending to drivers in the create requests, added as parameters, optional.
pvcNameKey = "csi.storage.k8s.io/pvc/name"
pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
pvNameKey = "csi.storage.k8s.io/pv/name"
pvcNameKey = "csi.storage.k8s.io/pvc/name"
pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
pvcNamespaceAnnotationsKey = "csi.storage.k8s.io/pvc/namespace/annotations"
pvNameKey = "csi.storage.k8s.io/pv/name"

snapshotKind = "VolumeSnapshot"
snapshotAPIGroup = snapapi.GroupName // "snapshot.storage.k8s.io"
Expand Down Expand Up @@ -716,9 +718,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
}

if p.extraCreateMetadata {
pvcAnnotationMap := claim.GetAnnotations()
vinli-cn marked this conversation as resolved.
Show resolved Hide resolved

pvcAnnotationPairs := []string{}
for k, v := range pvcAnnotationMap {
pvcAnnotationPairs = append(pvcAnnotationPairs, fmt.Sprintf("%s=%s", k, v))
}
sort.Strings(pvcAnnotationPairs)
pvcAnnotation := strings.Join(pvcAnnotationPairs, ",")

// add pvc and pv metadata to request for use by the plugin
req.Parameters[pvcNameKey] = claim.GetName()
req.Parameters[pvcNamespaceKey] = claim.GetNamespace()
req.Parameters[pvcNamespaceAnnotationsKey] = pvcAnnotation
req.Parameters[pvNameKey] = pvName
}
deletionAnnSecrets := new(deletionSecretParams)
Expand Down
18 changes: 13 additions & 5 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,14 @@ func provisionTestcases() (int64, map[string]provisioningTestcase) {
},
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
PVC: createFakeNamedPVC(
requestedBytes,
"fake-pvc",
map[string]string{
"userAnnotation1": "value1",
"userAnnotation2": "value2",
},
),
},
withExtraMetadata: true,
expectedPVSpec: &pvSpec{
Expand All @@ -1128,10 +1135,11 @@ func provisionTestcases() (int64, map[string]provisioningTestcase) {
expectCreateVolDo: func(t *testing.T, ctx context.Context, req *csi.CreateVolumeRequest) {
pvc := createFakePVC(requestedBytes)
expectedParams := map[string]string{
pvcNameKey: pvc.GetName(),
pvcNamespaceKey: pvc.GetNamespace(),
pvNameKey: "test-testi",
"fstype": "ext3",
pvcNameKey: pvc.GetName(),
pvcNamespaceKey: pvc.GetNamespace(),
pvNameKey: "test-testi",
"fstype": "ext3",
pvcNamespaceAnnotationsKey: "userAnnotation1=value1,userAnnotation2=value2,volume.beta.kubernetes.io/storage-provisioner=test-driver",
}
if fmt.Sprintf("%v", req.Parameters) != fmt.Sprintf("%v", expectedParams) { // only pvc name/namespace left
t.Errorf("Unexpected parameters: %v", req.Parameters)
Expand Down