mirror of https://github.com/k3s-io/k3s
set readOnly for CSI mounter
parent
f7d9fb474b
commit
4a3bdbecf9
|
@ -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...)
|
||||
|
|
Loading…
Reference in New Issue