Skip to content

Commit

Permalink
refactor(zfspv): renamed watcher to mgmt package
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pawanpraka1 authored and kmova committed Nov 26, 2019
1 parent e953af9 commit 523e862
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
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"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {
cmd.Flags().AddGoFlagSet(flag.CommandLine)

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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder {
if len(labels) == 0 {
b.errs = append(
b.errs,
errors.New("failed to build cstorvolume object: missing labels"),
errors.New("failed to build zfs volume object: missing labels"),
)
return b
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package driver
import (
"github.com/Sirupsen/logrus"
"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"
"github.com/openebs/zfs-localpv/pkg/builder"
"github.com/openebs/zfs-localpv/pkg/mgmt"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
Expand All @@ -42,9 +42,9 @@ func NewNode(d *CSIDriver) csi.NodeServer {
var ControllerMutex = sync.RWMutex{}
// start the zfsvolume watcher
go func() {
err := ctrl.Start(&ControllerMutex)
err := mgmt.Start(&ControllerMutex)
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())
}
}()

Expand Down
8 changes: 4 additions & 4 deletions pkg/driver/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/openebs/zfs-localpv/pkg/builder"
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
Expand All @@ -41,7 +41,7 @@ func volumeWeightedScheduler(topo *csi.TopologyRequirement, pool string) string
var selected string

zvlist, err := builder.NewKubeclient().
WithNamespace(zvol.OpenEBSNamespace).
WithNamespace(zfs.OpenEBSNamespace).
List(metav1.ListOptions{})

if err != nil {
Expand All @@ -63,7 +63,7 @@ func volumeWeightedScheduler(topo *csi.TopologyRequirement, pool string) string
// 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]
node := prf.Segments[zfs.ZFSTopologyKey]
if volmap[node] < numVol {
selected = node
numVol = volmap[node]
Expand All @@ -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 len(topo.Preferred) == 1 {
return topo.Preferred[0].Segments[zvol.ZFSTopologyKey]
return topo.Preferred[0].Segments[zfs.ZFSTopologyKey]
}

switch schld {
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/controller_base.go → pkg/mgmt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package mgmt

import (
"github.com/Sirupsen/logrus"
Expand Down
30 changes: 15 additions & 15 deletions cmd/controller/controller.go → pkg/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package mgmt

import (
"fmt"
Expand All @@ -23,7 +23,7 @@ import (
"github.com/Sirupsen/logrus"

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"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -80,42 +80,42 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
var err error
// ZFS Volume should be deleted. Check if deletion timestamp is set
if c.isDeletionCandidate(zv) {
err = zvol.DestroyVolume(zv)
err = zfs.DestroyVolume(zv)
if err == nil {
zvol.RemoveZvolFinalizer(zv)
zfs.RemoveZvolFinalizer(zv)
}
} else {
// if finalizer is not set then it means we are creating
// the volume. And if it is set then volume has already been
// created and this event is for property change only.
if zv.Finalizers != nil {
err = zvol.SetZvolProp(zv)
err = zfs.SetZvolProp(zv)
} else {
err = zvol.CreateVolume(zv)
err = zfs.CreateVolume(zv)
if err == nil {
err = zvol.UpdateZvolInfo(zv)
err = zfs.UpdateZvolInfo(zv)
}
}
}
return err
}

// addZV is the add event handler for CstorVolumeClaim
// addZV is the add event handler for ZFSVolume
func (c *ZVController) addZV(obj interface{}) {
zv, ok := obj.(*apis.ZFSVolume)
if !ok {
runtime.HandleError(fmt.Errorf("Couldn't get zv object %#v", obj))
return
}

if zvol.NodeID != zv.Spec.OwnerNodeID {
if zfs.NodeID != zv.Spec.OwnerNodeID {
return
}
logrus.Infof("Got add event for ZV %s/%s", zv.Spec.PoolName, zv.Name)
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{}) {

newZV, ok := newObj.(*apis.ZFSVolume)
Expand All @@ -124,19 +124,19 @@ func (c *ZVController) updateZV(oldObj, newObj interface{}) {
return
}

if zvol.NodeID != newZV.Spec.OwnerNodeID {
if zfs.NodeID != newZV.Spec.OwnerNodeID {
return
}

oldZV, ok := oldObj.(*apis.ZFSVolume)
if zvol.PropertyChanged(oldZV, newZV) ||
if zfs.PropertyChanged(oldZV, newZV) ||
c.isDeletionCandidate(newZV) {
logrus.Infof("Got update event for ZV %s/%s", newZV.Spec.PoolName, newZV.Name)
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{}) {
zv, ok := obj.(*apis.ZFSVolume)
if !ok {
Expand All @@ -147,12 +147,12 @@ func (c *ZVController) deleteZV(obj interface{}) {
}
zv, ok = tombstone.Obj.(*apis.ZFSVolume)
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
}
}

if zvol.NodeID != zv.Spec.OwnerNodeID {
if zfs.NodeID != zv.Spec.OwnerNodeID {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/start.go → pkg/mgmt/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package mgmt

import (
"sync"
Expand Down

0 comments on commit 523e862

Please sign in to comment.