Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(zfspv): renamed watcher to mgmt package #19

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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