Skip to content

Commit

Permalink
feat(schd): adding capacity weighted scheduler (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Feb 11, 2021
1 parent 7e0bd8a commit 311e12b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions changelogs/unreleased/20-akhilerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add capacity weighted scheduler and make it default for scheduling volumes
46 changes: 41 additions & 5 deletions pkg/driver/schd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ limitations under the License.
package driver

import (
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strconv"

"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
"github.com/openebs/lvm-localpv/pkg/lvm"
)

// scheduling algorithm constants
const (
// pick the node where less volumes are provisioned for the given volume group
// this will be the default scheduler when none provided
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"
)

// getVolumeWeightedMap goes through all the volumegroup on all the nodes
// and creats the node mapping of the volume for all the nodes.
// and creates the node mapping of the volume for all the nodes.
// It returns a map which has nodes as key and volumes present
// on the nodes as corresponding value.
func getVolumeWeightedMap(vg string) (map[string]int64, error) {
Expand All @@ -56,12 +60,44 @@ func getVolumeWeightedMap(vg string) (map[string]int64, error) {
return nmap, nil
}

// getCapacityWeightedMap goes through all the volume groups on all the nodes
// and creates the node mapping of the capacity for all the nodes.
// It returns a map which has nodes as key and capacity provisioned
// on the nodes as corresponding value. The scheduler will use this map
// and picks the node which is less weighted.
func getCapacityWeightedMap(vg string) (map[string]int64, error) {
nmap := map[string]int64{}

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

if err != nil {
return nmap, err
}

// create the map of the volume capacity
// for the given volume group
for _, vol := range volList.Items {
if vol.Spec.VolGroup == vg {
volSize, err := strconv.ParseInt(vol.Spec.Capacity, 10, 64)
if err == nil {
nmap[vol.Spec.OwnerNodeID] += volSize
}
}
}

return nmap, nil
}

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

0 comments on commit 311e12b

Please sign in to comment.