mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 05:02:50 +00:00
set readOnly for CSI mounter
This commit is contained in:
@@ -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(
|
|||||||
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
|
|||||||
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...)
|
||||||
|
Reference in New Issue
Block a user