set readOnly for CSI mounter

This commit is contained in:
mlmhl
2018-03-11 10:35:37 +08:00
parent f7d9fb474b
commit 4a3bdbecf9

View File

@@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter(
if err != nil {
return nil, err
}
readOnly, err := getReadOnlyFromSpec(spec)
if err != nil {
return nil, err
}
// before it is used in any paths such as socket etc
addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver)
@@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter(
volumeID: pvSource.VolumeHandle,
specVolumeID: spec.Name(),
csiClient: client,
readOnly: readOnly,
}
return mounter, nil
}
@@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er
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`
func log(msg string, parts ...interface{}) string {
return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...)