Skip to content

Commit

Permalink
feat(scheduler): adding SpaceWeighted scheduler (#178)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pawanpraka1 authored Mar 8, 2022
1 parent e41d25a commit 9cee6cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions deploy/lvm-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ metadata:
value: 900000000
globalDefault: false
description: "This priority class should be used for the OpenEBS LVM localPV CSI driver controller deployment only."

---

kind: StatefulSet
apiVersion: apps/v1
metadata:
Expand Down
47 changes: 44 additions & 3 deletions pkg/driver/schd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package driver

import (
"math"
"regexp"
"strconv"

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

"github.com/openebs/lvm-localpv/pkg/builder/nodebuilder"
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
"github.com/openebs/lvm-localpv/pkg/lvm"
)
Expand All @@ -32,8 +34,11 @@ const (
VolumeWeighted = "VolumeWeighted"

// pick the node where total provisioned volumes have occupied less capacity from the given volume group
// this will be the default scheduler when none provided
CapacityWeighted = "CapacityWeighted"

// pick the node which is less loaded space wise
// this will be the default scheduler when none provided
SpaceWeightedMap = "SpaceWeighted"
)

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

// getSpaceWeightedMap returns how weighted a node is space wise.
// The node which has max free space available is less loaded and
// can accumulate more volumes.
func getSpaceWeightedMap(re *regexp.Regexp) (map[string]int64, error) {
nmap := map[string]int64{}

nodeList, err := nodebuilder.NewKubeclient().
WithNamespace(lvm.LvmNamespace).
List(metav1.ListOptions{})

if err != nil {
return nmap, err
}

for _, node := range nodeList.Items {
var maxFree int64 = 0
for _, vg := range node.VolumeGroups {
if re.MatchString(vg.Name) {
freeCapacity := vg.Free.Value()
if maxFree < freeCapacity {
maxFree = freeCapacity
}
}
}
if maxFree > 0 {
// converting to SpaceWeighted by subtracting it with MaxInt64
// as the node which has max free space available is less loaded.
nmap[node.Name] = math.MaxInt64 - maxFree
}
}

return nmap, nil
}

// getNodeMap returns the node mapping for the given scheduling algorithm
func getNodeMap(schd string, vgPattern *regexp.Regexp) (map[string]int64, error) {
switch schd {
case VolumeWeighted:
return getVolumeWeightedMap(vgPattern)
case CapacityWeighted:
return getCapacityWeightedMap(vgPattern)
case SpaceWeightedMap:
return getSpaceWeightedMap(vgPattern)
}
// return CapacityWeighted(default) if not specified
return getCapacityWeightedMap(vgPattern)
// return getSpaceWeightedMap(default) if not specified
return getSpaceWeightedMap(vgPattern)
}

0 comments on commit 9cee6cb

Please sign in to comment.