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 ( import (
"fmt" "fmt"
"math"
"os" "os"
"path" "path"
"runtime" "runtime"
"strconv"
dstrings "strings" dstrings "strings"
"github.com/golang/glog" "github.com/golang/glog"
@ -63,6 +65,8 @@ const (
durabilityType = "replicate" durabilityType = "replicate"
secretKeyName = "key" // key name used in secret secretKeyName = "key" // key name used in secret
gciGlusterMountBinariesPath = "/sbin/mount.glusterfs" gciGlusterMountBinariesPath = "/sbin/mount.glusterfs"
defaultGidMin = 2000
defaultGidMax = math.MaxUint32
) )
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error { func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
@ -381,6 +385,8 @@ type provisioningConfig struct {
secretName string secretName string
secretValue string secretValue string
clusterId string clusterId string
gidMin uint32
gidMax uint32
} }
type glusterfsVolumeProvisioner struct { type glusterfsVolumeProvisioner struct {
@ -389,6 +395,16 @@ type glusterfsVolumeProvisioner struct {
options volume.VolumeOptions 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) { func (plugin *glusterfsPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
return plugin.newDeleterInternal(spec) return plugin.newDeleterInternal(spec)
} }
@ -681,6 +697,18 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa
cfg.clusterId = v cfg.clusterId = v
case "restauthenabled": case "restauthenabled":
authEnabled = dstrings.ToLower(v) == "true" 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: default:
return nil, fmt.Errorf("glusterfs: invalid option %q for volume plugin %s", k, glusterfsPluginName) 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 { } else {
cfg.secretValue = cfg.userKey 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 return &cfg, nil
} }

View File

@ -269,6 +269,8 @@ func TestParseClassParameters(t *testing.T) {
user: "admin", user: "admin",
userKey: "password", userKey: "password",
secretValue: "password", secretValue: "password",
gidMin: 2000,
gidMax: 4294967295,
}, },
}, },
{ {
@ -287,6 +289,8 @@ func TestParseClassParameters(t *testing.T) {
secretName: "mysecret", secretName: "mysecret",
secretNamespace: "default", secretNamespace: "default",
secretValue: "mypassword", secretValue: "mypassword",
gidMin: 2000,
gidMax: 4294967295,
}, },
}, },
{ {
@ -298,7 +302,9 @@ func TestParseClassParameters(t *testing.T) {
&secret, &secret,
false, // expect error false, // expect error
&provisioningConfig{ &provisioningConfig{
url: "https://localhost:8080", url: "https://localhost:8080",
gidMin: 2000,
gidMax: 4294967295,
}, },
}, },
{ {