Commit 92167b5b authored by Humble Chirammal's avatar Humble Chirammal Committed by Michael Adam

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

parent 11a5e84a
...@@ -18,9 +18,11 @@ package glusterfs ...@@ -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 ( ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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 ...@@ -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
} }
...@@ -269,6 +269,8 @@ func TestParseClassParameters(t *testing.T) { ...@@ -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) { ...@@ -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) { ...@@ -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,
}, },
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment