refactor(zfspv): renamed watcher to mgmt package

as it does the management task also corrected few logs
and renamed zvol to zfs(as we support zvol and dataset both)

Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
Pawan 2019-11-26 14:57:06 +05:30 committed by Kiran Mova
parent e953af99cf
commit 523e862159
7 changed files with 27 additions and 27 deletions

View file

@ -10,7 +10,7 @@ import (
config "github.com/openebs/zfs-localpv/pkg/config" config "github.com/openebs/zfs-localpv/pkg/config"
"github.com/openebs/zfs-localpv/pkg/driver" "github.com/openebs/zfs-localpv/pkg/driver"
"github.com/openebs/zfs-localpv/pkg/version" "github.com/openebs/zfs-localpv/pkg/version"
zvol "github.com/openebs/zfs-localpv/pkg/zfs" zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -39,7 +39,7 @@ func main() {
cmd.Flags().AddGoFlagSet(flag.CommandLine) cmd.Flags().AddGoFlagSet(flag.CommandLine)
cmd.PersistentFlags().StringVar( cmd.PersistentFlags().StringVar(
&config.NodeID, "nodeid", zvol.NodeID, "NodeID to identify the node running this driver", &config.NodeID, "nodeid", zfs.NodeID, "NodeID to identify the node running this driver",
) )
cmd.PersistentFlags().StringVar( cmd.PersistentFlags().StringVar(

View file

@ -200,7 +200,7 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder {
if len(labels) == 0 { if len(labels) == 0 {
b.errs = append( b.errs = append(
b.errs, b.errs,
errors.New("failed to build cstorvolume object: missing labels"), errors.New("failed to build zfs volume object: missing labels"),
) )
return b return b
} }

View file

@ -19,9 +19,9 @@ package driver
import ( import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
ctrl "github.com/openebs/zfs-localpv/cmd/controller"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1" apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
"github.com/openebs/zfs-localpv/pkg/builder" "github.com/openebs/zfs-localpv/pkg/builder"
"github.com/openebs/zfs-localpv/pkg/mgmt"
zfs "github.com/openebs/zfs-localpv/pkg/zfs" zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@ -42,9 +42,9 @@ func NewNode(d *CSIDriver) csi.NodeServer {
var ControllerMutex = sync.RWMutex{} var ControllerMutex = sync.RWMutex{}
// start the zfsvolume watcher // start the zfsvolume watcher
go func() { go func() {
err := ctrl.Start(&ControllerMutex) err := mgmt.Start(&ControllerMutex)
if err != nil { if err != nil {
logrus.Errorf("Failed to start cstorvolume claim controller: %s", err.Error()) logrus.Fatalf("Failed to start ZFS volume management controller: %s", err.Error())
} }
}() }()

View file

@ -24,7 +24,7 @@ import (
"github.com/openebs/zfs-localpv/pkg/builder" "github.com/openebs/zfs-localpv/pkg/builder"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
zvol "github.com/openebs/zfs-localpv/pkg/zfs" zfs "github.com/openebs/zfs-localpv/pkg/zfs"
) )
// scheduling algorithm constants // scheduling algorithm constants
@ -41,7 +41,7 @@ func volumeWeightedScheduler(topo *csi.TopologyRequirement, pool string) string
var selected string var selected string
zvlist, err := builder.NewKubeclient(). zvlist, err := builder.NewKubeclient().
WithNamespace(zvol.OpenEBSNamespace). WithNamespace(zfs.OpenEBSNamespace).
List(metav1.ListOptions{}) List(metav1.ListOptions{})
if err != nil { if err != nil {
@ -63,7 +63,7 @@ func volumeWeightedScheduler(topo *csi.TopologyRequirement, pool string) string
// schedule it on the node which has less // schedule it on the node which has less
// number of volume for the given pool // number of volume for the given pool
for _, prf := range topo.Preferred { for _, prf := range topo.Preferred {
node := prf.Segments[zvol.ZFSTopologyKey] node := prf.Segments[zfs.ZFSTopologyKey]
if volmap[node] < numVol { if volmap[node] < numVol {
selected = node selected = node
numVol = volmap[node] numVol = volmap[node]
@ -83,7 +83,7 @@ func scheduler(topo *csi.TopologyRequirement, schld string, pool string) string
} }
// if there is a single node, schedule it on that // if there is a single node, schedule it on that
if len(topo.Preferred) == 1 { if len(topo.Preferred) == 1 {
return topo.Preferred[0].Segments[zvol.ZFSTopologyKey] return topo.Preferred[0].Segments[zfs.ZFSTopologyKey]
} }
switch schld { switch schld {

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package controller package mgmt
import ( import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package controller package mgmt
import ( import (
"fmt" "fmt"
@ -23,7 +23,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1" apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
zvol "github.com/openebs/zfs-localpv/pkg/zfs" zfs "github.com/openebs/zfs-localpv/pkg/zfs"
k8serror "k8s.io/apimachinery/pkg/api/errors" k8serror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@ -80,27 +80,27 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
var err error var err error
// ZFS Volume should be deleted. Check if deletion timestamp is set // ZFS Volume should be deleted. Check if deletion timestamp is set
if c.isDeletionCandidate(zv) { if c.isDeletionCandidate(zv) {
err = zvol.DestroyVolume(zv) err = zfs.DestroyVolume(zv)
if err == nil { if err == nil {
zvol.RemoveZvolFinalizer(zv) zfs.RemoveZvolFinalizer(zv)
} }
} else { } else {
// if finalizer is not set then it means we are creating // if finalizer is not set then it means we are creating
// the volume. And if it is set then volume has already been // the volume. And if it is set then volume has already been
// created and this event is for property change only. // created and this event is for property change only.
if zv.Finalizers != nil { if zv.Finalizers != nil {
err = zvol.SetZvolProp(zv) err = zfs.SetZvolProp(zv)
} else { } else {
err = zvol.CreateVolume(zv) err = zfs.CreateVolume(zv)
if err == nil { if err == nil {
err = zvol.UpdateZvolInfo(zv) err = zfs.UpdateZvolInfo(zv)
} }
} }
} }
return err return err
} }
// addZV is the add event handler for CstorVolumeClaim // addZV is the add event handler for ZFSVolume
func (c *ZVController) addZV(obj interface{}) { func (c *ZVController) addZV(obj interface{}) {
zv, ok := obj.(*apis.ZFSVolume) zv, ok := obj.(*apis.ZFSVolume)
if !ok { if !ok {
@ -108,14 +108,14 @@ func (c *ZVController) addZV(obj interface{}) {
return return
} }
if zvol.NodeID != zv.Spec.OwnerNodeID { if zfs.NodeID != zv.Spec.OwnerNodeID {
return return
} }
logrus.Infof("Got add event for ZV %s/%s", zv.Spec.PoolName, zv.Name) logrus.Infof("Got add event for ZV %s/%s", zv.Spec.PoolName, zv.Name)
c.enqueueZV(zv) c.enqueueZV(zv)
} }
// updateZV is the update event handler for CstorVolumeClaim // updateZV is the update event handler for ZFSVolume
func (c *ZVController) updateZV(oldObj, newObj interface{}) { func (c *ZVController) updateZV(oldObj, newObj interface{}) {
newZV, ok := newObj.(*apis.ZFSVolume) newZV, ok := newObj.(*apis.ZFSVolume)
@ -124,19 +124,19 @@ func (c *ZVController) updateZV(oldObj, newObj interface{}) {
return return
} }
if zvol.NodeID != newZV.Spec.OwnerNodeID { if zfs.NodeID != newZV.Spec.OwnerNodeID {
return return
} }
oldZV, ok := oldObj.(*apis.ZFSVolume) oldZV, ok := oldObj.(*apis.ZFSVolume)
if zvol.PropertyChanged(oldZV, newZV) || if zfs.PropertyChanged(oldZV, newZV) ||
c.isDeletionCandidate(newZV) { c.isDeletionCandidate(newZV) {
logrus.Infof("Got update event for ZV %s/%s", newZV.Spec.PoolName, newZV.Name) logrus.Infof("Got update event for ZV %s/%s", newZV.Spec.PoolName, newZV.Name)
c.enqueueZV(newZV) c.enqueueZV(newZV)
} }
} }
// deleteZV is the delete event handler for CstorVolumeClaim // deleteZV is the delete event handler for ZFSVolume
func (c *ZVController) deleteZV(obj interface{}) { func (c *ZVController) deleteZV(obj interface{}) {
zv, ok := obj.(*apis.ZFSVolume) zv, ok := obj.(*apis.ZFSVolume)
if !ok { if !ok {
@ -147,12 +147,12 @@ func (c *ZVController) deleteZV(obj interface{}) {
} }
zv, ok = tombstone.Obj.(*apis.ZFSVolume) zv, ok = tombstone.Obj.(*apis.ZFSVolume)
if !ok { if !ok {
runtime.HandleError(fmt.Errorf("Tombstone contained object that is not a cstorvolumeclaim %#v", obj)) runtime.HandleError(fmt.Errorf("Tombstone contained object that is not a zfsvolume %#v", obj))
return return
} }
} }
if zvol.NodeID != zv.Spec.OwnerNodeID { if zfs.NodeID != zv.Spec.OwnerNodeID {
return return
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package controller package mgmt
import ( import (
"sync" "sync"