Unverified Commit 557de1e3 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #61011 from mlmhl/csi_readonly

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Set readOnly for CSI mounter **What this PR does / why we need it**: Currently the `csiMountMgr .readOnly` field is never set, we should set it to `Spec.ReadOnly`. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #61008 **Special notes for your reviewer**: Currently, most of the volume plugins use a `getVolumeSourceFromSpec` method to fetch `VolumeSource` and `ReadOnly` from `volume.Spec`. If the volume is an inline volume, `ReadOnly` is fetched from `Spec.Volume.<SpecificVolumeSource>.ReadOnly`, and if the volume is a `PersistentVolume`, `ReadOnly` is set to `Spec.Readonly`, which comes from `PersistentVolumeClaimVolumeSource.ReadOnly`. However, as CSI volume plugin is only supported in `PersistentVolume`, so we can just set `ReadOnly` to `Spec.ReadOnly`. **Release note**: ```release-note NONE ``` /sig storage
parents 17195553 4a3bdbec
...@@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter( ...@@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter(
if err != nil { if err != nil {
return nil, err return nil, err
} }
readOnly, err := getReadOnlyFromSpec(spec)
if err != nil {
return nil, err
}
// before it is used in any paths such as socket etc // before it is used in any paths such as socket etc
addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver) addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver)
...@@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter( ...@@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter(
volumeID: pvSource.VolumeHandle, volumeID: pvSource.VolumeHandle,
specVolumeID: spec.Name(), specVolumeID: spec.Name(),
csiClient: client, csiClient: client,
readOnly: readOnly,
} }
return mounter, nil return mounter, nil
} }
...@@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er ...@@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er
return nil, fmt.Errorf("CSIPersistentVolumeSource not defined in spec") return nil, fmt.Errorf("CSIPersistentVolumeSource not defined in spec")
} }
func getReadOnlyFromSpec(spec *volume.Spec) (bool, error) {
if spec.PersistentVolume != nil &&
spec.PersistentVolume.Spec.CSI != nil {
return spec.ReadOnly, nil
}
return false, fmt.Errorf("CSIPersistentVolumeSource not defined in spec")
}
// log prepends log string with `kubernetes.io/csi` // log prepends log string with `kubernetes.io/csi`
func log(msg string, parts ...interface{}) string { func log(msg string, parts ...interface{}) string {
return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...) return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment