Skip to content

Commit ca21efd

Browse files
authored
Merge pull request kubernetes#76983 from humblec/rotate
Shuffle addresslist for random mount server and cleanup error messages.
2 parents aff37ad + f30b14a commit ca21efd

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pkg/volume/glusterfs/glusterfs.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package glusterfs
1919
import (
2020
"fmt"
2121
"math"
22+
"math/rand"
2223
"os"
2324
"path/filepath"
2425
"runtime"
@@ -186,13 +187,13 @@ func (plugin *glusterfsPlugin) getEndpointNameAndNamespace(spec *volume.Spec, de
186187
}
187188
return endpoints, endpointsNs, nil
188189
}
189-
return "", "", fmt.Errorf("Spec does not reference a GlusterFS volume type")
190+
return "", "", fmt.Errorf("spec does not reference a GlusterFS volume type")
190191

191192
}
192193
func (plugin *glusterfsPlugin) newMounterInternal(spec *volume.Spec, ep *v1.Endpoints, pod *v1.Pod, mounter mount.Interface) (volume.Mounter, error) {
193194
volPath, readOnly, err := getVolumeInfo(spec)
194195
if err != nil {
195-
klog.Errorf("failed to get volumesource : %v", err)
196+
klog.Errorf("failed to get volumesource: %v", err)
196197
return nil, err
197198
}
198199
return &glusterfsMounter{
@@ -267,7 +268,7 @@ func (b *glusterfsMounter) CanMount() error {
267268
switch runtime.GOOS {
268269
case "linux":
269270
if _, err := exe.Run("test", "-x", gciLinuxGlusterMountBinaryPath); err != nil {
270-
return fmt.Errorf("Required binary %s is missing", gciLinuxGlusterMountBinaryPath)
271+
return fmt.Errorf("required binary %s is missing", gciLinuxGlusterMountBinaryPath)
271272
}
272273
}
273274
return nil
@@ -394,7 +395,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
394395
// Refer to backup-volfile-servers @ http://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Clients/
395396

396397
if (len(addrlist) > 0) && (addrlist[0] != "") {
397-
ip := addrlist[0]
398+
ip := addrlist[rand.Intn(len(addrlist))]
398399
errs = b.mounter.Mount(ip+":"+b.path, dir, "glusterfs", mountOptions)
399400
if errs == nil {
400401
klog.Infof("successfully mounted directory %s", dir)
@@ -427,7 +428,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
427428
// it all goes in a log file, we will read the log file
428429
logErr := readGlusterLog(log, b.pod.Name)
429430
if logErr != nil {
430-
return fmt.Errorf("mount failed: %v the following error information was pulled from the glusterfs log to help diagnose this issue: %v", errs, logErr)
431+
return fmt.Errorf("mount failed: %v, the following error information was pulled from the glusterfs log to help diagnose this issue: %v", errs, logErr)
431432
}
432433
return fmt.Errorf("mount failed: %v", errs)
433434

@@ -442,7 +443,7 @@ func getVolumeInfo(spec *volume.Spec) (string, bool, error) {
442443
spec.PersistentVolume.Spec.Glusterfs != nil {
443444
return spec.PersistentVolume.Spec.Glusterfs.Path, spec.ReadOnly, nil
444445
}
445-
return "", false, fmt.Errorf("Spec does not reference a Glusterfs volume type")
446+
return "", false, fmt.Errorf("spec does not reference a Glusterfs volume type")
446447
}
447448

448449
func (plugin *glusterfsPlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
@@ -743,7 +744,7 @@ func (p *glusterfsVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTop
743744
return nil, fmt.Errorf("%s does not support block volume provisioning", p.plugin.GetPluginName())
744745
}
745746

746-
klog.V(4).Infof("Provision VolumeOptions %v", p.options)
747+
klog.V(4).Infof("provision volume with options %v", p.options)
747748
scName := v1helper.GetPersistentVolumeClaimClass(p.options.PVC)
748749
cfg, err := parseClassParameters(p.options.Parameters, p.plugin.host.GetKubeClient())
749750
if err != nil {
@@ -762,7 +763,7 @@ func (p *glusterfsVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTop
762763
return nil, fmt.Errorf("failed to reserve GID from table: %v", err)
763764
}
764765

765-
klog.V(2).Infof("Allocated GID %d for PVC %s", gid, p.options.PVC.Name)
766+
klog.V(2).Infof("allocated GID %d for PVC %s", gid, p.options.PVC.Name)
766767

767768
glusterfs, sizeGiB, volID, err := p.CreateVolume(gid)
768769
if err != nil {
@@ -1162,21 +1163,21 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa
11621163
}
11631164

11641165
if cfg.gidMin > cfg.gidMax {
1165-
return nil, fmt.Errorf("StorageClass for provisioner %q must have gidMax value >= gidMin", glusterfsPluginName)
1166+
return nil, fmt.Errorf("storageClass for provisioner %q must have gidMax value >= gidMin", glusterfsPluginName)
11661167
}
11671168

11681169
if len(parseVolumeOptions) != 0 {
11691170
volOptions := dstrings.Split(parseVolumeOptions, ",")
11701171
if len(volOptions) == 0 {
1171-
return nil, fmt.Errorf("StorageClass for provisioner %q must have valid (for e.g., 'client.ssl on') volume option", glusterfsPluginName)
1172+
return nil, fmt.Errorf("storageClass for provisioner %q must have valid (for e.g., 'client.ssl on') volume option", glusterfsPluginName)
11721173
}
11731174
cfg.volumeOptions = volOptions
11741175

11751176
}
11761177

11771178
if len(parseVolumeNamePrefix) != 0 {
11781179
if dstrings.Contains(parseVolumeNamePrefix, "_") {
1179-
return nil, fmt.Errorf("Storageclass parameter 'volumenameprefix' should not contain '_' in its value")
1180+
return nil, fmt.Errorf("storageclass parameter 'volumenameprefix' should not contain '_' in its value")
11801181
}
11811182
cfg.volumeNamePrefix = parseVolumeNamePrefix
11821183
}
@@ -1217,7 +1218,7 @@ func getVolumeID(pv *v1.PersistentVolume, volumeName string) (string, error) {
12171218
func (plugin *glusterfsPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.Quantity, oldSize resource.Quantity) (resource.Quantity, error) {
12181219
pvSpec := spec.PersistentVolume.Spec
12191220
volumeName := pvSpec.Glusterfs.Path
1220-
klog.V(2).Infof("Received request to expand volume %s", volumeName)
1221+
klog.V(2).Infof("received request to expand volume %s", volumeName)
12211222
volumeID, err := getVolumeID(spec.PersistentVolume, volumeName)
12221223

12231224
if err != nil {

0 commit comments

Comments
 (0)