Skip to content

Commit 9cee6cb

Browse files
authored
feat(scheduler): adding SpaceWeighted scheduler (#178)
adding a new scheduler logic which selects the node which has max free space available. This is better scheduling algorithm than the volumeweighted and capacity weighted where we don't check for the free space available on the node. Signed-off-by: Pawan <[email protected]>
1 parent e41d25a commit 9cee6cb

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

deploy/lvm-operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,9 @@ metadata:
11601160
value: 900000000
11611161
globalDefault: false
11621162
description: "This priority class should be used for the OpenEBS LVM localPV CSI driver controller deployment only."
1163+
11631164
---
1165+
11641166
kind: StatefulSet
11651167
apiVersion: apps/v1
11661168
metadata:

pkg/driver/schd_helper.go

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ limitations under the License.
1717
package driver
1818

1919
import (
20+
"math"
2021
"regexp"
2122
"strconv"
2223

2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425

26+
"github.com/openebs/lvm-localpv/pkg/builder/nodebuilder"
2527
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
2628
"github.com/openebs/lvm-localpv/pkg/lvm"
2729
)
@@ -32,8 +34,11 @@ const (
3234
VolumeWeighted = "VolumeWeighted"
3335

3436
// pick the node where total provisioned volumes have occupied less capacity from the given volume group
35-
// this will be the default scheduler when none provided
3637
CapacityWeighted = "CapacityWeighted"
38+
39+
// pick the node which is less loaded space wise
40+
// this will be the default scheduler when none provided
41+
SpaceWeightedMap = "SpaceWeighted"
3742
)
3843

3944
// getVolumeWeightedMap goes through all the volumegroup on all the nodes
@@ -92,14 +97,50 @@ func getCapacityWeightedMap(re *regexp.Regexp) (map[string]int64, error) {
9297
return nmap, nil
9398
}
9499

100+
// getSpaceWeightedMap returns how weighted a node is space wise.
101+
// The node which has max free space available is less loaded and
102+
// can accumulate more volumes.
103+
func getSpaceWeightedMap(re *regexp.Regexp) (map[string]int64, error) {
104+
nmap := map[string]int64{}
105+
106+
nodeList, err := nodebuilder.NewKubeclient().
107+
WithNamespace(lvm.LvmNamespace).
108+
List(metav1.ListOptions{})
109+
110+
if err != nil {
111+
return nmap, err
112+
}
113+
114+
for _, node := range nodeList.Items {
115+
var maxFree int64 = 0
116+
for _, vg := range node.VolumeGroups {
117+
if re.MatchString(vg.Name) {
118+
freeCapacity := vg.Free.Value()
119+
if maxFree < freeCapacity {
120+
maxFree = freeCapacity
121+
}
122+
}
123+
}
124+
if maxFree > 0 {
125+
// converting to SpaceWeighted by subtracting it with MaxInt64
126+
// as the node which has max free space available is less loaded.
127+
nmap[node.Name] = math.MaxInt64 - maxFree
128+
}
129+
}
130+
131+
return nmap, nil
132+
}
133+
95134
// getNodeMap returns the node mapping for the given scheduling algorithm
96135
func getNodeMap(schd string, vgPattern *regexp.Regexp) (map[string]int64, error) {
97136
switch schd {
98137
case VolumeWeighted:
99138
return getVolumeWeightedMap(vgPattern)
100139
case CapacityWeighted:
101140
return getCapacityWeightedMap(vgPattern)
141+
case SpaceWeightedMap:
142+
return getSpaceWeightedMap(vgPattern)
102143
}
103-
// return CapacityWeighted(default) if not specified
104-
return getCapacityWeightedMap(vgPattern)
144+
// return getSpaceWeightedMap(default) if not specified
145+
return getSpaceWeightedMap(vgPattern)
105146
}

0 commit comments

Comments
 (0)