mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
This patch add a new parameter called snapfactor
to glusterfs
storageclass. This is an optional parameter and value should fall into the range of 1-100. When set the thin pool calculation respect this snapfactor and create a thinpool accordingly. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
2ef566d0c3
commit
f7957e848b
@ -409,6 +409,7 @@ type provisionerConfig struct {
|
||||
volumeType gapi.VolumeDurabilityInfo
|
||||
volumeOptions []string
|
||||
volumeNamePrefix string
|
||||
thinPoolSnapFactor float32
|
||||
}
|
||||
|
||||
type glusterfsVolumeProvisioner struct {
|
||||
@ -760,7 +761,15 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsVolum
|
||||
}
|
||||
|
||||
gid64 := int64(gid)
|
||||
volumeReq := &gapi.VolumeCreateRequest{Size: sz, Name: customVolumeName, Clusters: clusterIDs, Gid: gid64, Durability: p.volumeType, GlusterVolumeOptions: p.volumeOptions}
|
||||
snaps := struct {
|
||||
Enable bool `json:"enable"`
|
||||
Factor float32 `json:"factor"`
|
||||
}{
|
||||
true,
|
||||
p.provisionerConfig.thinPoolSnapFactor,
|
||||
}
|
||||
|
||||
volumeReq := &gapi.VolumeCreateRequest{Size: sz, Name: customVolumeName, Clusters: clusterIDs, Gid: gid64, Durability: p.volumeType, GlusterVolumeOptions: p.volumeOptions, Snapshot: snaps}
|
||||
volume, err := cli.VolumeCreate(volumeReq)
|
||||
if err != nil {
|
||||
glog.Errorf("failed to create volume: %v", err)
|
||||
@ -927,6 +936,10 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa
|
||||
parseVolumeType := ""
|
||||
parseVolumeOptions := ""
|
||||
parseVolumeNamePrefix := ""
|
||||
parseThinPoolSnapFactor := ""
|
||||
|
||||
//thin pool snap factor default to 1.0
|
||||
cfg.thinPoolSnapFactor = float32(1.0)
|
||||
|
||||
for k, v := range params {
|
||||
switch dstrings.ToLower(k) {
|
||||
@ -981,6 +994,11 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa
|
||||
if len(v) != 0 {
|
||||
parseVolumeNamePrefix = v
|
||||
}
|
||||
case "snapfactor":
|
||||
if len(v) != 0 {
|
||||
parseThinPoolSnapFactor = v
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, glusterfsPluginName)
|
||||
}
|
||||
@ -1068,6 +1086,17 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa
|
||||
}
|
||||
cfg.volumeNamePrefix = parseVolumeNamePrefix
|
||||
}
|
||||
|
||||
if len(parseThinPoolSnapFactor) != 0 {
|
||||
thinPoolSnapFactor, err := strconv.ParseFloat(parseThinPoolSnapFactor, 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert snapfactor %v to float: %v", parseThinPoolSnapFactor, err)
|
||||
}
|
||||
if thinPoolSnapFactor < 1.0 || thinPoolSnapFactor > 100.0 {
|
||||
return nil, fmt.Errorf("invalid snapshot factor %v, the value must be between 1 to 100", thinPoolSnapFactor)
|
||||
}
|
||||
cfg.thinPoolSnapFactor = float32(thinPoolSnapFactor)
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
|
@ -260,6 +260,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 2000,
|
||||
gidMax: 2147483647,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -281,6 +282,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 2000,
|
||||
gidMax: 2147483647,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -296,6 +298,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 2000,
|
||||
gidMax: 2147483647,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -433,6 +436,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 4000,
|
||||
gidMax: 2147483647,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -449,6 +453,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 2000,
|
||||
gidMax: 5000,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -466,6 +471,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 4000,
|
||||
gidMax: 5000,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
|
||||
@ -485,6 +491,7 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 4000,
|
||||
gidMax: 5000,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 4}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
|
||||
@ -504,6 +511,27 @@ func TestParseClassParameters(t *testing.T) {
|
||||
gidMin: 4000,
|
||||
gidMax: 5000,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "disperse", Replicate: gapi.ReplicaDurability{Replica: 0}, Disperse: gapi.DisperseDurability{Data: 4, Redundancy: 2}},
|
||||
thinPoolSnapFactor: float32(1.0),
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid snapfactor: 50",
|
||||
map[string]string{
|
||||
"resturl": "https://localhost:8080",
|
||||
"restauthenabled": "false",
|
||||
"gidMin": "4000",
|
||||
"gidMax": "5000",
|
||||
"volumetype": "disperse:4:2",
|
||||
"snapfactor": "50",
|
||||
},
|
||||
&secret,
|
||||
false, // expect error
|
||||
&provisionerConfig{
|
||||
url: "https://localhost:8080",
|
||||
gidMin: 4000,
|
||||
gidMax: 5000,
|
||||
volumeType: gapi.VolumeDurabilityInfo{Type: "disperse", Replicate: gapi.ReplicaDurability{Replica: 0}, Disperse: gapi.DisperseDurability{Data: 4, Redundancy: 2}},
|
||||
thinPoolSnapFactor: float32(50),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -550,6 +578,28 @@ func TestParseClassParameters(t *testing.T) {
|
||||
true, // expect error
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"invalid thinPoolSnapFactor: value out of range",
|
||||
map[string]string{
|
||||
"resturl": "https://localhost:8080",
|
||||
"restauthenabled": "false",
|
||||
"snapfactor": "0.5",
|
||||
},
|
||||
&secret,
|
||||
true, // expect error
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"invalid thinPoolSnapFactor: value out of range",
|
||||
map[string]string{
|
||||
"resturl": "https://localhost:8080",
|
||||
"restauthenabled": "false",
|
||||
"snapfactor": "120",
|
||||
},
|
||||
&secret,
|
||||
true, // expect error
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user