diff --git a/.gitignore b/.gitignore index ab11c5c1..c095246e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tags *.swp *.swo *.swn +*.idea diff --git a/pkg/builder/snapbuilder/build.go b/pkg/builder/snapbuilder/build.go index a2ff6dff..c19a2750 100644 --- a/pkg/builder/snapbuilder/build.go +++ b/pkg/builder/snapbuilder/build.go @@ -101,6 +101,8 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder { return b } +// WithFinalizer merge existing finalizers if any +// with the ones that are provided here func (b *Builder) WithFinalizer(finalizer []string) *Builder { b.snap.Object.Finalizers = append(b.snap.Object.Finalizers, finalizer...) return b diff --git a/pkg/builder/volbuilder/build.go b/pkg/builder/volbuilder/build.go index 703080da..e73f7fa1 100644 --- a/pkg/builder/volbuilder/build.go +++ b/pkg/builder/volbuilder/build.go @@ -178,6 +178,7 @@ func (b *Builder) WithSnapshot(snap string) *Builder { return b } +// WithPoolName sets Pool name for creating volume func (b *Builder) WithPoolName(pool string) *Builder { if pool == "" { b.errs = append( @@ -192,7 +193,8 @@ func (b *Builder) WithPoolName(pool string) *Builder { return b } -func (b *Builder) WithNodename(name string) *Builder { +// WithNodeName sets NodeID for creating the volume +func (b *Builder) WithNodeName(name string) *Builder { if name == "" { b.errs = append( b.errs, @@ -223,6 +225,7 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder { return b } +// WithFinalizer sets Finalizer name creating the volume func (b *Builder) WithFinalizer(finalizer []string) *Builder { b.volume.Object.Finalizers = append(b.volume.Object.Finalizers, finalizer...) return b diff --git a/pkg/client/k8s/v1alpha1/namespace.go b/pkg/client/k8s/v1alpha1/namespace.go index fc4af404..cbd6bb97 100644 --- a/pkg/client/k8s/v1alpha1/namespace.go +++ b/pkg/client/k8s/v1alpha1/namespace.go @@ -22,7 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// Namespacegetter abstracts fetching of Namespace from kubernetes cluster +// NamespaceGetter abstracts fetching of Namespace from kubernetes cluster type NamespaceGetter interface { Get(name string, options metav1.GetOptions) (*corev1.Namespace, error) } @@ -43,9 +43,8 @@ func (ns *namespace) Get(name string, options metav1.GetOptions) (*corev1.Namesp cs, err := Clientset().Get() if err != nil { return nil, errors.Wrapf(err, "failed to get namespace: %s", name) - } else { - return cs.CoreV1().Namespaces().Get(name, options) } + return cs.CoreV1().Namespaces().Get(name, options) } // List returns a slice of namespaces defined in a Kubernetes cluster @@ -53,7 +52,6 @@ func (ns *namespace) List(options metav1.ListOptions) (*corev1.NamespaceList, er cs, err := Clientset().Get() if err != nil { return nil, errors.Wrapf(err, "failed to get namespaces") - } else { - return cs.CoreV1().Namespaces().List(options) } + return cs.CoreV1().Namespaces().List(options) } diff --git a/pkg/common/env/env.go b/pkg/common/env/env.go index 3f6905dc..9c19fd50 100644 --- a/pkg/common/env/env.go +++ b/pkg/common/env/env.go @@ -64,9 +64,8 @@ func GetOrDefault(e string, defaultValue string) (value string) { if len(envValue) == 0 { // ENV not defined or set to "" return defaultValue - } else { - return envValue } + return envValue } // Lookup looks up an environment variable diff --git a/pkg/common/kubernetes/client/client.go b/pkg/common/kubernetes/client/client.go index 93fa0276..8ae394c7 100644 --- a/pkg/common/kubernetes/client/client.go +++ b/pkg/common/kubernetes/client/client.go @@ -212,11 +212,12 @@ func (c *Client) Config() (config *rest.Config, err error) { return c.getInClusterConfig() } -// ConfigForPath returns the kuberentes config instance based on KubeConfig path +// ConfigForPath returns the kubernetes config instance based on KubeConfig path func (c *Client) ConfigForPath(kubeConfigPath string) (config *rest.Config, err error) { return c.buildConfigFromFlags("", kubeConfigPath) } +// GetConfigForPathOrDirect returns the kubernetes config instance based on direct KubeConfig func (c *Client) GetConfigForPathOrDirect() (config *rest.Config, err error) { if c.KubeConfigPath != "" { return c.ConfigForPath(c.KubeConfigPath) diff --git a/pkg/driver/agent.go b/pkg/driver/agent.go index 19fdee87..1d66b272 100644 --- a/pkg/driver/agent.go +++ b/pkg/driver/agent.go @@ -69,6 +69,7 @@ func NewNode(d *CSIDriver) csi.NodeServer { } } +// GetVolAndMountInfo get volume and mount info from node csi volume request func GetVolAndMountInfo( req *csi.NodePublishVolumeRequest, ) (*apis.ZFSVolume, *apis.MountInfo, error) { diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 1855c73c..6895dbd2 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -24,6 +24,10 @@ import ( "github.com/Sirupsen/logrus" "github.com/container-storage-interface/spec/lib/go/csi" + "golang.org/x/net/context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/openebs/zfs-localpv/pkg/builder/snapbuilder" "github.com/openebs/zfs-localpv/pkg/builder/volbuilder" errors "github.com/openebs/zfs-localpv/pkg/common/errors" @@ -31,9 +35,6 @@ import ( csipayload "github.com/openebs/zfs-localpv/pkg/response" analytics "github.com/openebs/zfs-localpv/pkg/usage" zfs "github.com/openebs/zfs-localpv/pkg/zfs" - "golang.org/x/net/context" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // controller is the server implementation @@ -74,6 +75,7 @@ func sendEventOrIgnore(pvcName, pvName, capacity, stgType, method string) { } } +// CreateZFSVolume create new zfs volume from csi volume request func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) { volName := req.GetName() size := req.GetCapacityRange().RequiredBytes @@ -137,6 +139,7 @@ func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) { return selected, nil } +// CreateZFSClone create a clone of zfs volume func CreateZFSClone(req *csi.CreateVolumeRequest, snapshot string) (string, error) { volName := req.GetName() @@ -260,6 +263,14 @@ func (cs *controller) DeleteVolume( goto deleteResponse } + if err != nil { + return nil, errors.Wrapf( + err, + "failed to get volume for {%s}", + volumeID, + ) + } + // Delete the corresponding ZV CR err = zfs.DeleteVolume(volumeID) if err != nil { diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 1c146da2..f27defa3 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -29,10 +29,9 @@ var supportedAccessMode = &csi.VolumeCapability_AccessMode{ Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, } -// TODO check if this can be renamed to Base -// // CSIDriver defines a common data structure // for drivers +// TODO check if this can be renamed to Base type CSIDriver struct { // TODO change the field names to make it // readable diff --git a/pkg/driver/grpc.go b/pkg/driver/grpc.go index 82f8e438..c93dcb7e 100644 --- a/pkg/driver/grpc.go +++ b/pkg/driver/grpc.go @@ -75,22 +75,22 @@ type NonBlockingGRPCServer interface { // NewNonBlockingGRPCServer returns a new instance of NonBlockingGRPCServer func NewNonBlockingGRPCServer(ep string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) NonBlockingGRPCServer { return &nonBlockingGRPCServer{ - endpoint: ep, - idnty_server: ids, - ctrl_server: cs, - agent_server: ns} + endpoint: ep, + idntyServer: ids, + ctrlServer: cs, + agentServer: ns} } // NonBlocking server // dont block the execution for a task to complete. // use wait group to wait for all the tasks dispatched. type nonBlockingGRPCServer struct { - wg sync.WaitGroup - server *grpc.Server - endpoint string - idnty_server csi.IdentityServer - ctrl_server csi.ControllerServer - agent_server csi.NodeServer + wg sync.WaitGroup + server *grpc.Server + endpoint string + idntyServer csi.IdentityServer + ctrlServer csi.ControllerServer + agentServer csi.NodeServer } // Start grpc server for serving CSI endpoints @@ -98,7 +98,7 @@ func (s *nonBlockingGRPCServer) Start() { s.wg.Add(1) - go s.serve(s.endpoint, s.idnty_server, s.ctrl_server, s.agent_server) + go s.serve(s.endpoint, s.idntyServer, s.ctrlServer, s.agentServer) return } diff --git a/pkg/mgmt/volume/volume.go b/pkg/mgmt/volume/volume.go index ce909c39..d2201bc6 100644 --- a/pkg/mgmt/volume/volume.go +++ b/pkg/mgmt/volume/volume.go @@ -131,7 +131,7 @@ func (c *ZVController) updateZV(oldObj, newObj interface{}) { return } - oldZV, ok := oldObj.(*apis.ZFSVolume) + oldZV, _ := oldObj.(*apis.ZFSVolume) if zfs.PropertyChanged(oldZV, newZV) || c.isDeletionCandidate(newZV) { logrus.Infof("Got update event for ZV %s/%s", newZV.Spec.PoolName, newZV.Name) diff --git a/pkg/response/create.go b/pkg/response/create.go index d798efc6..da0cff1c 100644 --- a/pkg/response/create.go +++ b/pkg/response/create.go @@ -43,7 +43,7 @@ func (b *CreateVolumeResponseBuilder) WithName(name string) *CreateVolumeRespons return b } -// WithName sets the capacity against the +// WithCapacity sets the capacity against the // CreateVolumeResponse instance func (b *CreateVolumeResponseBuilder) WithCapacity(capacity int64) *CreateVolumeResponseBuilder { b.response.Volume.CapacityBytes = capacity diff --git a/pkg/usage/const.go b/pkg/usage/const.go index d92b5105..c4ee2d6b 100644 --- a/pkg/usage/const.go +++ b/pkg/usage/const.go @@ -21,26 +21,28 @@ const ( // supported events categories - // Install event is sent on pod starts + // InstallEvent event is sent on pod starts InstallEvent string = "install" // Ping event is sent periodically Ping string = "zfs-ping" // VolumeProvision event is sent when a volume is created VolumeProvision string = "volume-provision" - //VolumeDeprovision event is sent when a volume is deleted + // VolumeDeprovision event is sent when a volume is deleted VolumeDeprovision string = "volume-deprovision" - AppName string = "OpenEBS" + // AppName the application name + AppName string = "OpenEBS" + // RunningStatus status is running + RunningStatus string = "running" // Event labels - RunningStatus string = "running" EventLabelNode string = "nodes" EventLabelCapacity string = "capacity" - // Event action + // Replica Event replication Replica string = "replica:" DefaultReplicaCount string = "replica:1" - // Event application name constant for volume event + // DefaultCASType Event application name constant for volume event DefaultCASType string = "zfs-localpv" // LocalPVReplicaCount is the constant used by usage to represent diff --git a/pkg/usage/googleanalytics.go b/pkg/usage/googleanalytics.go index beb7aaeb..6aa8c122 100644 --- a/pkg/usage/googleanalytics.go +++ b/pkg/usage/googleanalytics.go @@ -13,6 +13,7 @@ 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 usage import ( diff --git a/pkg/usage/ping.go b/pkg/usage/ping.go index dfb8633d..5029a325 100644 --- a/pkg/usage/ping.go +++ b/pkg/usage/ping.go @@ -22,6 +22,7 @@ import ( "github.com/openebs/zfs-localpv/pkg/common/env" ) +// OpenEBSPingPeriod ping interval of volume io analytics var OpenEBSPingPeriod = "OPENEBS_IO_ANALYTICS_PING_INTERVAL" const ( @@ -39,7 +40,7 @@ func PingCheck() { u := New() duration := getPingPeriod() ticker := time.NewTicker(duration) - for _ = range ticker.C { + for range ticker.C { u.Build(). InstallBuilder(true). SetCategory(Ping). @@ -57,7 +58,8 @@ func getPingPeriod() time.Duration { if duration < minimumPingPeriod { // Avoid corner case when the ENV value is undesirable return time.Duration(defaultPingPeriod) - } else { - return time.Duration(duration) } + + return time.Duration(duration) + } diff --git a/pkg/usage/usage.go b/pkg/usage/usage.go index b4cc8a2e..fcf7de7e 100644 --- a/pkg/usage/usage.go +++ b/pkg/usage/usage.go @@ -13,6 +13,7 @@ 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 usage import ( @@ -204,7 +205,7 @@ func (u *Usage) Build() *Usage { return u } -// Application builder is used for adding k8s&openebs environment detail +// ApplicationBuilder Application builder is used for adding k8s&openebs environment detail // for non install events func (u *Usage) ApplicationBuilder() *Usage { v := NewVersion() @@ -223,7 +224,7 @@ func (u *Usage) SetVolumeCapacity(volCapG string) *Usage { return u } -// Wrapper for setting the default storage-engine for volume-provision event +// SetVolumeType Wrapper for setting the default storage-engine for volume-provision event func (u *Usage) SetVolumeType(volType, method string) *Usage { if method == VolumeProvision && volType == "" { // Set the default storage engine, if not specified in the request @@ -234,7 +235,7 @@ func (u *Usage) SetVolumeType(volType, method string) *Usage { return u } -// Wrapper for setting replica count for volume events +// SetReplicaCount Wrapper for setting replica count for volume events // NOTE: This doesn't get the replica count in a volume de-provision event. // TODO: Pick the current value of replica-count from the CAS-engine func (u *Usage) SetReplicaCount(count, method string) *Usage { @@ -244,7 +245,7 @@ func (u *Usage) SetReplicaCount(count, method string) *Usage { u.SetAction(DefaultReplicaCount) } else { // Catch all case for volume-deprovision event and - // volume-provision event with an overriden replica-count + // volume-provision event with an overridden replica-count u.SetAction(Replica + count) } return u diff --git a/pkg/usage/versionset.go b/pkg/usage/versionset.go index f4cfe537..fded4060 100644 --- a/pkg/usage/versionset.go +++ b/pkg/usage/versionset.go @@ -13,6 +13,7 @@ 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 usage import ( diff --git a/pkg/version/version.go b/pkg/version/version.go index 55ec8485..18f5f3d8 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -108,6 +108,7 @@ func GetGitCommit() string { return strings.TrimSpace(string(output)) } +// GetVersionDetails return version info from git commit func GetVersionDetails() string { return "zfs-" + strings.Join([]string{Get(), GetGitCommit()[0:7]}, "-") } diff --git a/pkg/zfs/mount.go b/pkg/zfs/mount.go index 5dd2e71e..845c4254 100644 --- a/pkg/zfs/mount.go +++ b/pkg/zfs/mount.go @@ -235,7 +235,7 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error { return nil } -// MountVolume mounts the disk to the specified path +// MountFilesystem mounts the disk to the specified path func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error { switch vol.Spec.VolumeType { case VOLTYPE_DATASET: @@ -245,6 +245,7 @@ func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error { } } +// MountBlock mounts the block disk to the specified path func MountBlock(vol *apis.ZFSVolume, mountinfo *apis.MountInfo) error { target := mountinfo.MountPath devicePath := ZFS_DEVPATH + vol.Spec.PoolName + "/" + vol.Name diff --git a/pkg/zfs/volume.go b/pkg/zfs/volume.go index 364bcedb..e79d0920 100644 --- a/pkg/zfs/volume.go +++ b/pkg/zfs/volume.go @@ -27,11 +27,11 @@ import ( ) const ( - // OpenEBSNamespace is the environment variable to get openebs namespace + // OpenEBSNamespaceKey is the environment variable to get openebs namespace // // This environment variable is set via kubernetes downward API OpenEBSNamespaceKey string = "OPENEBS_NAMESPACE" - // This environment variable is set via env + // GoogleAnalyticsKey This environment variable is set via env GoogleAnalyticsKey string = "OPENEBS_IO_ENABLE_ANALYTICS" // ZFSFinalizer for the ZfsVolume CR ZFSFinalizer string = "zfs.openebs.io/finalizer" @@ -56,7 +56,7 @@ var ( // NodeID is the NodeID of the node on which the pod is present NodeID string - // should send google analytics or not + // GoogleAnalyticsEnabled should send google analytics or not GoogleAnalyticsEnabled string ) diff --git a/pkg/zfs/xfs_util.go b/pkg/zfs/xfs_util.go index 256779ce..1921cfaf 100644 --- a/pkg/zfs/xfs_util.go +++ b/pkg/zfs/xfs_util.go @@ -24,7 +24,7 @@ import ( "strings" ) -func xfs_temp_mount(volume string) error { +func xfsTempMount(volume string) error { device := ZFS_DEVPATH + volume pvol := strings.Split(volume, "/") @@ -69,11 +69,11 @@ func xfs_temp_mount(volume string) error { * There might be something there in the xfs log, we have to clear them * so that filesystem is clean and we can generate the UUID for it. */ -func xfs_generate_uuid(volume string) error { +func xfsGenerateUuid(volume string) error { device := ZFS_DEVPATH + volume // temporary mount the volume with nouuid to replay the logs - err := xfs_temp_mount(volume) + err := xfsTempMount(volume) if err != nil { return err } diff --git a/pkg/zfs/zfs_util.go b/pkg/zfs/zfs_util.go index d16638dc..16118364 100644 --- a/pkg/zfs/zfs_util.go +++ b/pkg/zfs/zfs_util.go @@ -49,6 +49,7 @@ const ( VOLTYPE_ZVOL = "ZVOL" ) +// PropertyChanged return whether volume property is changed func PropertyChanged(oldVol *apis.ZFSVolume, newVol *apis.ZFSVolume) bool { if oldVol.Spec.VolumeType == VOLTYPE_DATASET && newVol.Spec.VolumeType == VOLTYPE_DATASET && @@ -363,7 +364,7 @@ func CreateClone(vol *apis.ZFSVolume) error { } if vol.Spec.FsType == "xfs" { - return xfs_generate_uuid(volume) + return xfsGenerateUuid(volume) } return nil } @@ -597,6 +598,7 @@ func GetVolumeDevPath(vol *apis.ZFSVolume) (string, error) { return dev, nil } +// ResizeZFSVolume resize volume func ResizeZFSVolume(vol *apis.ZFSVolume, mountpath string) error { volume := vol.Spec.PoolName + "/" + vol.Name diff --git a/tests/deploy/deployment.go b/tests/deploy/deployment.go index 7e814826..518ae846 100644 --- a/tests/deploy/deployment.go +++ b/tests/deploy/deployment.go @@ -171,7 +171,7 @@ func (b *Builder) WithNodeSelector(selector map[string]string) *Builder { return b } -// WithNodeSelector Sets the node selector with the provided argument. +// WithNodeSelectorNew Sets the node selector with the provided argument. func (b *Builder) WithNodeSelectorNew(selector map[string]string) *Builder { if len(selector) == 0 { b.errors = append( diff --git a/tests/deploy/kubernetes.go b/tests/deploy/kubernetes.go index 6263e303..ab712edb 100644 --- a/tests/deploy/kubernetes.go +++ b/tests/deploy/kubernetes.go @@ -13,6 +13,7 @@ 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 deploy import ( diff --git a/tests/pod/pod.go b/tests/pod/pod.go index c42f69e2..654c62f4 100644 --- a/tests/pod/pod.go +++ b/tests/pod/pod.go @@ -73,7 +73,7 @@ func (l predicateList) all(p *Pod) bool { return true } -// IsRunning retuns true if the pod is in running +// IsRunning returns true if the pod is in running // state func (p *Pod) IsRunning() bool { return p.object.Status.Phase == "Running" @@ -87,7 +87,7 @@ func IsRunning() Predicate { } } -// IsCompleted retuns true if the pod is in completed +// IsCompleted returns true if the pod is in completed // state func (p *Pod) IsCompleted() bool { return p.object.Status.Phase == "Succeeded"