glusterfs: teach provisioner to extract gid-range from storage class

This commit is contained in:
Humble Chirammal 2016-12-02 02:16:23 +01:00 committed by Michael Adam
parent 11a5e84aca
commit 92167b5be8
2 changed files with 48 additions and 1 deletions

View File

@ -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
}

View File

@ -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,
},
},
{