mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-11 22:10:11 +01:00
Application can now create a storageclass to create zfs filesystem apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: openebs-zfspv5 allowVolumeExpansion: true parameters: blocksize: "4k" fstype: "zfs" poolname: "zfspv-pool" provisioner: zfs.csi.openebs.io ZFSPV was supporting ext2/3/4 and xfs filesystem only which adds one extra filesystem layer on top of ZFS filesystem. So now we can driectly write to the ZFS filesystem and get the optimal performance by directly creating ZFS filesystem for storage. Signed-off-by: Pawan <pawan@mayadata.io>
97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
/*
|
|
Copyright © 2019 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/Sirupsen/logrus"
|
|
"math"
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
|
"github.com/openebs/zfs-localpv/pkg/builder"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
zvol "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"
|
|
)
|
|
|
|
// volumeWeightedScheduler goes through all the pools on the nodes mentioned
|
|
// in the topology and picks the node which has less volume on
|
|
// the given zfs pool.
|
|
func volumeWeightedScheduler(topo *csi.TopologyRequirement, pool string) string {
|
|
var selected string
|
|
|
|
zvlist, err := builder.NewKubeclient().
|
|
WithNamespace(zvol.OpenEBSNamespace).
|
|
List(metav1.ListOptions{})
|
|
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
volmap := map[string]int{}
|
|
|
|
// create the map of the volume count
|
|
// for the given pool
|
|
for _, zv := range zvlist.Items {
|
|
if zv.Spec.PoolName == pool {
|
|
volmap[zv.Spec.OwnerNodeID]++
|
|
}
|
|
}
|
|
|
|
var numVol int = math.MaxInt32
|
|
|
|
// schedule it on the node which has less
|
|
// number of volume for the given pool
|
|
for _, prf := range topo.Preferred {
|
|
node := prf.Segments[zvol.ZFSTopologyKey]
|
|
if volmap[node] < numVol {
|
|
selected = node
|
|
numVol = volmap[node]
|
|
}
|
|
}
|
|
return selected
|
|
}
|
|
|
|
// scheduler schedules the PV as per topology constraints for
|
|
// the given zfs pool.
|
|
func scheduler(topo *csi.TopologyRequirement, schld string, pool string) string {
|
|
|
|
if topo == nil ||
|
|
len(topo.Preferred) == 0 {
|
|
logrus.Errorf("topology information not provided")
|
|
return ""
|
|
}
|
|
// if there is a single node, schedule it on that
|
|
if len(topo.Preferred) == 1 {
|
|
return topo.Preferred[0].Segments[zvol.ZFSTopologyKey]
|
|
}
|
|
|
|
switch schld {
|
|
case VolumeWeighted:
|
|
return volumeWeightedScheduler(topo, pool)
|
|
default:
|
|
return volumeWeightedScheduler(topo, pool)
|
|
}
|
|
|
|
return ""
|
|
}
|