mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #59097 from zhangxiaoyu-zidif/delete-redundant-get-volumesource
Automatic merge from submit-queue (batch tested with PRs 59097, 57076, 59295). 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>. delete duplicate function for getting volume source **What this PR does / why we need it**: these two methods have same function. ```go func getVolumeSource( spec *volume.Spec) (*v1.GlusterfsVolumeSource, bool, error) { if spec.Volume != nil && spec.Volume.Glusterfs != nil { return spec.Volume.Glusterfs, spec.Volume.Glusterfs.ReadOnly, nil } else if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Glusterfs != nil { return spec.PersistentVolume.Spec.Glusterfs, spec.ReadOnly, nil } return nil, false, fmt.Errorf("Spec does not reference a Glusterfs volume type") } func (plugin *glusterfsPlugin) getGlusterVolumeSource(spec *volume.Spec) (*v1.GlusterfsVolumeSource, bool) { // Glusterfs volumes used directly in a pod have a ReadOnly flag set by the pod author. // Glusterfs volumes used as a PersistentVolume gets the ReadOnly flag indirectly through the persistent-claim volume used to mount the PV if spec.Volume != nil && spec.Volume.Glusterfs != nil { return spec.Volume.Glusterfs, spec.Volume.Glusterfs.ReadOnly } return spec.PersistentVolume.Spec.Glusterfs, spec.ReadOnly } ``` `getVolumeSource` seems to be much better. **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 # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
a8581f41e6
@ -143,7 +143,11 @@ func (plugin *glusterfsPlugin) GetAccessModes() []v1.PersistentVolumeAccessMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *glusterfsPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.Mounter, error) {
|
func (plugin *glusterfsPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.Mounter, error) {
|
||||||
source, _ := plugin.getGlusterVolumeSource(spec)
|
source, _, err := getVolumeSource(spec)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("failed to get gluster volumesource: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
epName := source.EndpointsName
|
epName := source.EndpointsName
|
||||||
// PVC/POD is in same ns.
|
// PVC/POD is in same ns.
|
||||||
podNs := pod.Namespace
|
podNs := pod.Namespace
|
||||||
@ -160,17 +164,8 @@ func (plugin *glusterfsPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volu
|
|||||||
return plugin.newMounterInternal(spec, ep, pod, plugin.host.GetMounter(plugin.GetPluginName()))
|
return plugin.newMounterInternal(spec, ep, pod, plugin.host.GetMounter(plugin.GetPluginName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *glusterfsPlugin) getGlusterVolumeSource(spec *volume.Spec) (*v1.GlusterfsVolumeSource, bool) {
|
|
||||||
// Glusterfs volumes used directly in a pod have a ReadOnly flag set by the pod author.
|
|
||||||
// Glusterfs volumes used as a PersistentVolume gets the ReadOnly flag indirectly through the persistent-claim volume used to mount the PV
|
|
||||||
if spec.Volume != nil && spec.Volume.Glusterfs != nil {
|
|
||||||
return spec.Volume.Glusterfs, spec.Volume.Glusterfs.ReadOnly
|
|
||||||
}
|
|
||||||
return spec.PersistentVolume.Spec.Glusterfs, spec.ReadOnly
|
|
||||||
}
|
|
||||||
|
|
||||||
func (plugin *glusterfsPlugin) newMounterInternal(spec *volume.Spec, ep *v1.Endpoints, pod *v1.Pod, mounter mount.Interface) (volume.Mounter, error) {
|
func (plugin *glusterfsPlugin) newMounterInternal(spec *volume.Spec, ep *v1.Endpoints, pod *v1.Pod, mounter mount.Interface) (volume.Mounter, error) {
|
||||||
source, readOnly := plugin.getGlusterVolumeSource(spec)
|
source, readOnly, _ := getVolumeSource(spec)
|
||||||
return &glusterfsMounter{
|
return &glusterfsMounter{
|
||||||
glusterfs: &glusterfs{
|
glusterfs: &glusterfs{
|
||||||
volName: spec.Name(),
|
volName: spec.Name(),
|
||||||
@ -379,8 +374,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVolumeSource(
|
func getVolumeSource(spec *volume.Spec) (*v1.GlusterfsVolumeSource, bool, error) {
|
||||||
spec *volume.Spec) (*v1.GlusterfsVolumeSource, bool, error) {
|
|
||||||
if spec.Volume != nil && spec.Volume.Glusterfs != nil {
|
if spec.Volume != nil && spec.Volume.Glusterfs != nil {
|
||||||
return spec.Volume.Glusterfs, spec.Volume.Glusterfs.ReadOnly, nil
|
return spec.Volume.Glusterfs, spec.Volume.Glusterfs.ReadOnly, nil
|
||||||
} else if spec.PersistentVolume != nil &&
|
} else if spec.PersistentVolume != nil &&
|
||||||
|
Loading…
Reference in New Issue
Block a user