mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 14:30:12 +01:00
This is an initial scheduler implementation for ZFS Local PV.
* adding scheduler as a configurable option
* adding volumeWeightedScheduler as scheduling logic
The volumeWeightedScheduler will go through all the nodes as per
topology information and it will pick the node which has less
volume provisioned in the given pool.
lets say there are 2 nodes node1 and node2 with below pool configuration :-
```
node1
|
|-----> pool1
| |
| |------> pvc1
| |------> pvc2
|-----> pool2
|------> pvc3
node2
|
|-----> pool1
| |
| |------> pvc4
|-----> pool2
|------> pvc5
|------> pvc6
```
So if application is using pool1 as shown in the below storage class, then ZFS driver will schedule it on node2 as it has one volume as compared to node1 which has 2 volumes in pool1.
```yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: openebs-zfspv
provisioner: zfs.csi.openebs.io
parameters:
blocksize: "4k"
compression: "on"
dedup: "on"
thinprovision: "yes"
poolname: "pool1"
```
So if application is using pool2 as shown in the below storage class, then ZFS driver will schedule it on node1 as it has one volume only as compared node2 which has 2 volumes in pool2.
```yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: openebs-zfspv
provisioner: zfs.csi.openebs.io
parameters:
blocksize: "4k"
compression: "on"
dedup: "on"
thinprovision: "yes"
poolname: "pool2"
```
In case of same number of volumes on all the nodes for the given pool, it can pick any node and schedule the PV on that.
Signed-off-by: Pawan <pawan@mayadata.io>
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
config "github.com/openebs/zfs-localpv/pkg/config"
|
|
"github.com/openebs/zfs-localpv/pkg/driver"
|
|
"github.com/openebs/zfs-localpv/pkg/version"
|
|
zvol "github.com/openebs/zfs-localpv/pkg/zfs"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
/*
|
|
* main routine to start the zfs-driver. The same
|
|
* binary is used to controller and agent deployment.
|
|
* they both are differentiated via plugin command line
|
|
* argument. To start the controller, we have to pass
|
|
* --plugin=controller and to start it as agent, we have
|
|
* to pass --plugin=agent.
|
|
*/
|
|
func main() {
|
|
_ = flag.CommandLine.Parse([]string{})
|
|
var config = config.Default()
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "zfs-driver",
|
|
Short: "driver for provisioning zfs volume",
|
|
Long: `provisions and deprovisions the volume
|
|
on the node which has zfs pool configured.`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
run(config)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().AddGoFlagSet(flag.CommandLine)
|
|
|
|
cmd.PersistentFlags().StringVar(
|
|
&config.NodeID, "nodeid", zvol.NodeID, "NodeID to identify the node running this driver",
|
|
)
|
|
|
|
cmd.PersistentFlags().StringVar(
|
|
&config.Version, "version", "", "Displays driver version",
|
|
)
|
|
|
|
cmd.PersistentFlags().StringVar(
|
|
&config.Endpoint, "endpoint", "unix://csi/csi.sock", "CSI endpoint",
|
|
)
|
|
|
|
cmd.PersistentFlags().StringVar(
|
|
&config.DriverName, "name", "zfs.csi.openebs.io", "Name of this driver",
|
|
)
|
|
|
|
cmd.PersistentFlags().StringVar(
|
|
&config.PluginType, "plugin", "csi-plugin", "Type of this driver i.e. controller or node",
|
|
)
|
|
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
_, _ = fmt.Fprintf(os.Stderr, "%s", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(config *config.Config) {
|
|
if config.Version == "" {
|
|
config.Version = version.Current()
|
|
}
|
|
|
|
logrus.Infof("%s - %s", version.Current(), version.GetGitCommit())
|
|
logrus.Infof(
|
|
"DriverName: %s Plugin: %s EndPoint: %s NodeID: %s",
|
|
config.DriverName,
|
|
config.PluginType,
|
|
config.Endpoint,
|
|
config.NodeID,
|
|
)
|
|
|
|
err := driver.New(config).Run()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
os.Exit(0)
|
|
}
|