diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 5f234b5ee66..ddb95250902 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -18,9 +18,11 @@ package glusterfs import ( "fmt" + "math" "os" "path" "runtime" + "strconv" dstrings "strings" "github.com/golang/glog" @@ -63,6 +65,8 @@ const ( durabilityType = "replicate" secretKeyName = "key" // key name used in secret gciGlusterMountBinariesPath = "/sbin/mount.glusterfs" + defaultGidMin = 2000 + defaultGidMax = math.MaxUint32 ) func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error { @@ -381,6 +385,8 @@ type provisioningConfig struct { secretName string secretValue string clusterId string + gidMin uint32 + gidMax uint32 } type glusterfsVolumeProvisioner struct { @@ -389,6 +395,16 @@ type glusterfsVolumeProvisioner struct { options volume.VolumeOptions } +func convertGid(inputGid string) (uint32, error) { + inputGid32, err := strconv.ParseUint(inputGid, 10, 32); + if err != nil { + glog.Errorf("glusterfs: failed to parse gid %v ", inputGid) + return 0, fmt.Errorf("glusterfs: failed to parse gid %v ", inputGid) + } + outputGid := uint32(inputGid32) + return outputGid, nil +} + func (plugin *glusterfsPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) { return plugin.newDeleterInternal(spec) } @@ -681,6 +697,18 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa cfg.clusterId = v case "restauthenabled": authEnabled = dstrings.ToLower(v) == "true" + case "gidmin": + parseGidMin, err := convertGid(v) + if err != nil { + return nil, fmt.Errorf("glusterfs: invalid value %q for volume plugin %s", k, glusterfsPluginName) + } + cfg.gidMin = parseGidMin + case "gidmax": + parseGidMax, err := convertGid(v) + if err != nil { + return nil, fmt.Errorf("glusterfs: invalid value %q for volume plugin %s", k, glusterfsPluginName) + } + cfg.gidMax = parseGidMax default: return nil, fmt.Errorf("glusterfs: invalid option %q for volume plugin %s", k, glusterfsPluginName) } @@ -711,5 +739,18 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa } else { cfg.secretValue = cfg.userKey } + + if cfg.gidMin == 0 { + cfg.gidMin = defaultGidMin + } + + if cfg.gidMax == 0 { + cfg.gidMax = defaultGidMax + } + + if cfg.gidMin > cfg.gidMax { + return nil, fmt.Errorf("StorageClass for provisioner %q must have gidMax value >= gidMin", glusterfsPluginName) + } + return &cfg, nil } diff --git a/pkg/volume/glusterfs/glusterfs_test.go b/pkg/volume/glusterfs/glusterfs_test.go index 30dc37f1b47..34e3f91bc5e 100644 --- a/pkg/volume/glusterfs/glusterfs_test.go +++ b/pkg/volume/glusterfs/glusterfs_test.go @@ -269,6 +269,8 @@ func TestParseClassParameters(t *testing.T) { user: "admin", userKey: "password", secretValue: "password", + gidMin: 2000, + gidMax: 4294967295, }, }, { @@ -287,6 +289,8 @@ func TestParseClassParameters(t *testing.T) { secretName: "mysecret", secretNamespace: "default", secretValue: "mypassword", + gidMin: 2000, + gidMax: 4294967295, }, }, { @@ -298,7 +302,9 @@ func TestParseClassParameters(t *testing.T) { &secret, false, // expect error &provisioningConfig{ - url: "https://localhost:8080", + url: "https://localhost:8080", + gidMin: 2000, + gidMax: 4294967295, }, }, {