mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
glusterfs: Fix all gid types to int to prevent failures on 32bit systems
This makes all types int until we hand the GID to heketi/gluster, at which point it's converted to int64. It also limits the maximum usable GID ti math.MaxInt32 = 2147483647. Signed-off-by: Michael Adam <obnox@redhat.com>
This commit is contained in:
parent
06ad835e48
commit
8a1752f2bb
@ -94,7 +94,7 @@ When both `restuserkey` and `secretNamespace` + `secretName` is specified, the s
|
|||||||
|
|
||||||
Example of a secret can be found in [glusterfs-provisioning-secret.yaml](glusterfs-provisioning-secret.yaml).
|
Example of a secret can be found in [glusterfs-provisioning-secret.yaml](glusterfs-provisioning-secret.yaml).
|
||||||
|
|
||||||
* `gidMin` + `gidMax` : The minimum and maximum value of GID range for the storage class. A unique value (GID) in this range ( gidMin-gidMax ) will be used for dynamically provisioned volumes. These are optional values. If not specified, the volume will be provisioned with a value between 2000-4294967295 which are defaults for gidMin and gidMax respectively.
|
* `gidMin` + `gidMax` : The minimum and maximum value of GID range for the storage class. A unique value (GID) in this range ( gidMin-gidMax ) will be used for dynamically provisioned volumes. These are optional values. If not specified, the volume will be provisioned with a value between 2000-2147483647 which are defaults for gidMin and gidMax respectively.
|
||||||
|
|
||||||
Reference : ([How to configure Heketi](https://github.com/heketi/heketi/wiki/Setting-up-the-topology))
|
Reference : ([How to configure Heketi](https://github.com/heketi/heketi/wiki/Setting-up-the-topology))
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ const (
|
|||||||
secretKeyName = "key" // key name used in secret
|
secretKeyName = "key" // key name used in secret
|
||||||
gciGlusterMountBinariesPath = "/sbin/mount.glusterfs"
|
gciGlusterMountBinariesPath = "/sbin/mount.glusterfs"
|
||||||
defaultGidMin = 2000
|
defaultGidMin = 2000
|
||||||
defaultGidMax = math.MaxUint32
|
defaultGidMax = math.MaxInt32
|
||||||
absoluteGidMax = math.MaxUint32
|
absoluteGidMax = math.MaxInt32
|
||||||
)
|
)
|
||||||
|
|
||||||
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
|
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
|
||||||
@ -392,8 +392,8 @@ type provisioningConfig struct {
|
|||||||
secretName string
|
secretName string
|
||||||
secretValue string
|
secretValue string
|
||||||
clusterId string
|
clusterId string
|
||||||
gidMin uint32
|
gidMin int
|
||||||
gidMax uint32
|
gidMax int
|
||||||
}
|
}
|
||||||
|
|
||||||
type glusterfsVolumeProvisioner struct {
|
type glusterfsVolumeProvisioner struct {
|
||||||
@ -402,13 +402,20 @@ type glusterfsVolumeProvisioner struct {
|
|||||||
options volume.VolumeOptions
|
options volume.VolumeOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertGid(inputGid string) (uint32, error) {
|
func convertGid(gidString string) (int, error) {
|
||||||
inputGid32, err := strconv.ParseUint(inputGid, 10, 32)
|
gid64, err := strconv.ParseInt(gidString, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("glusterfs: failed to parse gid %v ", inputGid)
|
return 0, fmt.Errorf("glusterfs: failed to parse gid %v ", gidString)
|
||||||
}
|
}
|
||||||
outputGid := uint32(inputGid32)
|
|
||||||
return outputGid, nil
|
if gid64 < 0 {
|
||||||
|
return 0, fmt.Errorf("glusterfs: negative GIDs are not allowed: %v", gidString)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseInt returns a int64, but since we parsed only
|
||||||
|
// for 32 bit, we can cast to int without loss:
|
||||||
|
gid := int(gid64)
|
||||||
|
return gid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *glusterfsPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
|
func (plugin *glusterfsPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
|
||||||
@ -473,7 +480,7 @@ func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocato
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = gidTable.Allocate(int(gid))
|
_, err = gidTable.Allocate(gid)
|
||||||
if err == ErrConflict {
|
if err == ErrConflict {
|
||||||
glog.Warningf("glusterfs: gid %v found in pv %v was already allocated", gid)
|
glog.Warningf("glusterfs: gid %v found in pv %v was already allocated", gid)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -491,14 +498,14 @@ func (p *glusterfsPlugin) collectGids(className string, gidTable *MinMaxAllocato
|
|||||||
// used in PVs of this storage class by traversing the PVs.
|
// used in PVs of this storage class by traversing the PVs.
|
||||||
// - Adapt the range of the table to the current range of the SC.
|
// - Adapt the range of the table to the current range of the SC.
|
||||||
//
|
//
|
||||||
func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32) (*MinMaxAllocator, error) {
|
func (p *glusterfsPlugin) getGidTable(className string, min int, max int) (*MinMaxAllocator, error) {
|
||||||
var err error
|
var err error
|
||||||
p.gidTableLock.Lock()
|
p.gidTableLock.Lock()
|
||||||
gidTable, ok := p.gidTable[className]
|
gidTable, ok := p.gidTable[className]
|
||||||
p.gidTableLock.Unlock()
|
p.gidTableLock.Unlock()
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
err = gidTable.SetRange(int(min), int(max))
|
err = gidTable.SetRange(min, max)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -519,7 +526,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// and only reduce the range afterwards
|
// and only reduce the range afterwards
|
||||||
err = newGidTable.SetRange(int(min), int(max))
|
err = newGidTable.SetRange(min, max)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -531,7 +538,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
|
|||||||
|
|
||||||
gidTable, ok = p.gidTable[className]
|
gidTable, ok = p.gidTable[className]
|
||||||
if ok {
|
if ok {
|
||||||
err = gidTable.SetRange(int(min), int(max))
|
err = gidTable.SetRange(min, max)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -544,7 +551,7 @@ func (p *glusterfsPlugin) getGidTable(className string, min uint32, max uint32)
|
|||||||
return newGidTable, nil
|
return newGidTable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *glusterfsVolumeDeleter) getGid() (uint32, bool, error) {
|
func (d *glusterfsVolumeDeleter) getGid() (int, bool, error) {
|
||||||
gidStr, ok := d.spec.Annotations[volumehelper.VolumeGidAnnotationKey]
|
gidStr, ok := d.spec.Annotations[volumehelper.VolumeGidAnnotationKey]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -583,7 +590,7 @@ func (d *glusterfsVolumeDeleter) Delete() error {
|
|||||||
return fmt.Errorf("glusterfs: failed to get gidTable: %v", err)
|
return fmt.Errorf("glusterfs: failed to get gidTable: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gidTable.Release(int(gid))
|
err = gidTable.Release(gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("glusterfs: failed to release gid %v: %v", gid, err)
|
return fmt.Errorf("glusterfs: failed to release gid %v: %v", gid, err)
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ func TestParseClassParameters(t *testing.T) {
|
|||||||
userKey: "password",
|
userKey: "password",
|
||||||
secretValue: "password",
|
secretValue: "password",
|
||||||
gidMin: 2000,
|
gidMin: 2000,
|
||||||
gidMax: 4294967295,
|
gidMax: 2147483647,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -290,7 +290,7 @@ func TestParseClassParameters(t *testing.T) {
|
|||||||
secretNamespace: "default",
|
secretNamespace: "default",
|
||||||
secretValue: "mypassword",
|
secretValue: "mypassword",
|
||||||
gidMin: 2000,
|
gidMin: 2000,
|
||||||
gidMax: 4294967295,
|
gidMax: 2147483647,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -304,7 +304,7 @@ func TestParseClassParameters(t *testing.T) {
|
|||||||
&provisioningConfig{
|
&provisioningConfig{
|
||||||
url: "https://localhost:8080",
|
url: "https://localhost:8080",
|
||||||
gidMin: 2000,
|
gidMin: 2000,
|
||||||
gidMax: 4294967295,
|
gidMax: 2147483647,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user