mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 22:40:12 +01:00
feat(schd): adding capacity weighted scheduler
The ZFS Driver will use capacity scheduler to pick a node which has less capacity occupied by the volumes. Making this as default scheduler as it is better than the volume count based scheduling. We can use below storageclass to specify the scheduler ```yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: openebs-zfspv allowVolumeExpansion: true parameters: scheduler: "CapacityWeighted" poolname: "zfspv-pool" provisioner: zfs.csi.openebs.io ``` Please Note that after the upgrade, there will be a change in the behavior. If we are not using `scheduler` parameter in the storage class then after the upgrade ZFS Driver will pick the node bases on volume capacity weight instead of the count. Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
e0fbce805b
commit
90ecfe9c73
2 changed files with 41 additions and 4 deletions
1
changelogs/unreleased/266-pawanpraka1
Normal file
1
changelogs/unreleased/266-pawanpraka1
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
adding capacity weighted scheduler
|
||||||
|
|
@ -19,6 +19,7 @@ package driver
|
||||||
import (
|
import (
|
||||||
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
|
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
|
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
|
||||||
)
|
)
|
||||||
|
|
@ -26,12 +27,15 @@ import (
|
||||||
// scheduling algorithm constants
|
// scheduling algorithm constants
|
||||||
const (
|
const (
|
||||||
// pick the node where less volumes are provisioned for the given pool
|
// pick the node where less volumes are provisioned for the given pool
|
||||||
// this will be the default scheduler when none provided
|
|
||||||
VolumeWeighted = "VolumeWeighted"
|
VolumeWeighted = "VolumeWeighted"
|
||||||
|
|
||||||
|
// pick the node where total provisioned volumes have occupied less capacity from the given pool
|
||||||
|
// this will be the default scheduler when none provided
|
||||||
|
CapacityWeighted = "CapacityWeighted"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getVolumeWeightedMap goes through all the pools on all the nodes
|
// getVolumeWeightedMap goes through all the pools 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
|
// It returns a map which has nodes as key and volumes present
|
||||||
// on the nodes as corresponding value.
|
// on the nodes as corresponding value.
|
||||||
func getVolumeWeightedMap(pool string) (map[string]int64, error) {
|
func getVolumeWeightedMap(pool string) (map[string]int64, error) {
|
||||||
|
|
@ -56,12 +60,44 @@ func getVolumeWeightedMap(pool string) (map[string]int64, error) {
|
||||||
return nmap, nil
|
return nmap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getCapacityWeightedMap goes through all the pools 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(pool string) (map[string]int64, error) {
|
||||||
|
nmap := map[string]int64{}
|
||||||
|
|
||||||
|
zvlist, err := volbuilder.NewKubeclient().
|
||||||
|
WithNamespace(zfs.OpenEBSNamespace).
|
||||||
|
List(metav1.ListOptions{})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nmap, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the map of the volume capacity
|
||||||
|
// for the given pool
|
||||||
|
for _, zv := range zvlist.Items {
|
||||||
|
if zv.Spec.PoolName == pool {
|
||||||
|
volsize, err := strconv.ParseInt(zv.Spec.Capacity, 10, 64)
|
||||||
|
if err == nil {
|
||||||
|
nmap[zv.Spec.OwnerNodeID] += volsize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nmap, nil
|
||||||
|
}
|
||||||
|
|
||||||
// getNodeMap returns the node mapping for the given scheduling algorithm
|
// getNodeMap returns the node mapping for the given scheduling algorithm
|
||||||
func getNodeMap(schd string, pool string) (map[string]int64, error) {
|
func getNodeMap(schd string, pool string) (map[string]int64, error) {
|
||||||
switch schd {
|
switch schd {
|
||||||
case VolumeWeighted:
|
case VolumeWeighted:
|
||||||
return getVolumeWeightedMap(pool)
|
return getVolumeWeightedMap(pool)
|
||||||
|
case CapacityWeighted:
|
||||||
|
return getCapacityWeightedMap(pool)
|
||||||
}
|
}
|
||||||
// return VolumeWeighted(default) if not specified
|
// return CapacityWeighted(default) if not specified
|
||||||
return getVolumeWeightedMap(pool)
|
return getCapacityWeightedMap(pool)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue