Skip to content

Commit 311e12b

Browse files
authored
feat(schd): adding capacity weighted scheduler (#20)
Signed-off-by: Akhil Mohan <[email protected]>
1 parent 7e0bd8a commit 311e12b

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

changelogs/unreleased/20-akhilerm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add capacity weighted scheduler and make it default for scheduling volumes

pkg/driver/schd_helper.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ limitations under the License.
1717
package driver
1818

1919
import (
20-
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
2120
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"strconv"
2222

23+
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
2324
"github.com/openebs/lvm-localpv/pkg/lvm"
2425
)
2526

2627
// scheduling algorithm constants
2728
const (
2829
// pick the node where less volumes are provisioned for the given volume group
29-
// this will be the default scheduler when none provided
3030
VolumeWeighted = "VolumeWeighted"
31+
32+
// pick the node where total provisioned volumes have occupied less capacity from the given volume group
33+
// this will be the default scheduler when none provided
34+
CapacityWeighted = "CapacityWeighted"
3135
)
3236

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

63+
// getCapacityWeightedMap goes through all the volume groups on all the nodes
64+
// and creates the node mapping of the capacity for all the nodes.
65+
// It returns a map which has nodes as key and capacity provisioned
66+
// on the nodes as corresponding value. The scheduler will use this map
67+
// and picks the node which is less weighted.
68+
func getCapacityWeightedMap(vg string) (map[string]int64, error) {
69+
nmap := map[string]int64{}
70+
71+
volList, err := volbuilder.NewKubeclient().
72+
WithNamespace(lvm.LvmNamespace).
73+
List(metav1.ListOptions{})
74+
75+
if err != nil {
76+
return nmap, err
77+
}
78+
79+
// create the map of the volume capacity
80+
// for the given volume group
81+
for _, vol := range volList.Items {
82+
if vol.Spec.VolGroup == vg {
83+
volSize, err := strconv.ParseInt(vol.Spec.Capacity, 10, 64)
84+
if err == nil {
85+
nmap[vol.Spec.OwnerNodeID] += volSize
86+
}
87+
}
88+
}
89+
90+
return nmap, nil
91+
}
92+
5993
// getNodeMap returns the node mapping for the given scheduling algorithm
6094
func getNodeMap(schd string, vg string) (map[string]int64, error) {
6195
switch schd {
6296
case VolumeWeighted:
6397
return getVolumeWeightedMap(vg)
98+
case CapacityWeighted:
99+
return getCapacityWeightedMap(vg)
64100
}
65-
// return VolumeWeighted(default) if not specified
66-
return getVolumeWeightedMap(vg)
101+
// return CapacityWeighted(default) if not specified
102+
return getCapacityWeightedMap(vg)
67103
}

0 commit comments

Comments
 (0)