-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor): refactor scheduler for ZFS-LocalPV
Signed-off-by: Pawan <pawan@mayadata.io>
- Loading branch information
1 parent
30a7f23
commit ef1b0ed
Showing
3 changed files
with
91 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2020 The OpenEBS Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package driver | ||
|
||
import ( | ||
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
zfs "github.com/openebs/zfs-localpv/pkg/zfs" | ||
) | ||
|
||
// scheduling algorithm constants | ||
const ( | ||
// pick the node where less volumes are provisioned for the given pool | ||
// this will be the default scheduler when none provided | ||
VolumeWeighted = "VolumeWeighted" | ||
) | ||
|
||
// getVolumeWeightedMap goes through all the pools on all the nodes | ||
// and creats 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(pool string) (error, map[string]int64) { | ||
nmap := map[string]int64{} | ||
|
||
zvlist, err := volbuilder.NewKubeclient(). | ||
WithNamespace(zfs.OpenEBSNamespace). | ||
List(metav1.ListOptions{}) | ||
|
||
if err != nil { | ||
return err, nmap | ||
} | ||
|
||
// create the map of the volume count | ||
// for the given pool | ||
for _, zv := range zvlist.Items { | ||
if zv.Spec.PoolName == pool { | ||
nmap[zv.Spec.OwnerNodeID]++ | ||
} | ||
} | ||
|
||
return nil, nmap | ||
} | ||
|
||
// getNodeMap returns the node mapping for the given scheduling algorithm | ||
func getNodeMap(schd string, pool string) (error, map[string]int64) { | ||
switch schd { | ||
case VolumeWeighted: | ||
return getVolumeWeightedMap(pool) | ||
} | ||
// return VolumeWeighted(default) if not specified | ||
return getVolumeWeightedMap(pool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters