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

Add functionality to set pv gid annotation via driver volumecontext #1339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"k8s.io/klog/v2"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v11/controller"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v11/util"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v11/gidallocator"

"github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
Expand Down Expand Up @@ -121,6 +122,9 @@ const (
pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
pvNameKey = "csi.storage.k8s.io/pv/name"

// GID metadata key to add to PV annotation if returned in volume context
gidCsiKey = "csi.storage.k8s.io/pv.gid"

snapshotKind = "VolumeSnapshot"
snapshotAPIGroup = snapapi.GroupName // "snapshot.storage.k8s.io"
pvcKind = "PersistentVolumeClaim" // Native types don't require an API group
Expand Down Expand Up @@ -933,6 +937,11 @@ func (p *csiProvisioner) Provision(ctx context.Context, options controller.Provi
metav1.SetMetaDataAnnotation(&pv.ObjectMeta, annDeletionProvisionerSecretRefNamespace, "")
}

if gid, ok := volumeAttributes[gidCsiKey]; ok {
Copy link
Contributor

@AndrewSirenko AndrewSirenko Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having provisioner reach into volumeAttributes like this violates CSI Spec.

volumeAttributes comes from CSI CreateVolumeResponse.volume.volume_context, which according to CSI Spec shall be opaque to CO (and therefore csi-provisioner)

// Opaque static properties of the volume. SP MAY use this field to
// ensure subsequent volume validation and publishing calls have
// contextual information.
// The contents of this field SHALL be opaque to a CO.

source

metav1.SetMetaDataAnnotation(&pv.ObjectMeta, gidallocator.VolumeGidAnnotationKey, gid)
delete(result.csiPVSource.VolumeAttributes, gidCsiKey)
}

if options.StorageClass.ReclaimPolicy != nil {
pv.Spec.PersistentVolumeReclaimPolicy = *options.StorageClass.ReclaimPolicy
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,10 @@ sigs.k8s.io/json
sigs.k8s.io/json/internal/golang/encoding/json
# sigs.k8s.io/sig-storage-lib-external-provisioner/v11 v11.0.1
## explicit; go 1.22.0
sigs.k8s.io/sig-storage-lib-external-provisioner/v11/allocator
sigs.k8s.io/sig-storage-lib-external-provisioner/v11/controller
sigs.k8s.io/sig-storage-lib-external-provisioner/v11/controller/metrics
sigs.k8s.io/sig-storage-lib-external-provisioner/v11/gidallocator
sigs.k8s.io/sig-storage-lib-external-provisioner/v11/util
# sigs.k8s.io/structured-merge-diff/v4 v4.5.0
## explicit; go 1.13
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading