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

fix(golint): fixing golint warnings #133

Merged
merged 6 commits into from
Jun 9, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tags
*.swp
*.swo
*.swn
*.idea
2 changes: 2 additions & 0 deletions pkg/builder/snapbuilder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/builder/volbuilder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions pkg/client/k8s/v1alpha1/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -43,17 +43,15 @@ 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
func (ns *namespace) List(options metav1.ListOptions) (*corev1.NamespaceList, error) {
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)
}
3 changes: 1 addition & 2 deletions pkg/common/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/common/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 14 additions & 3 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ 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"
"github.com/openebs/zfs-localpv/pkg/common/helpers"
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions pkg/driver/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,30 @@ 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
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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mgmt/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/response/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions pkg/usage/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/usage/googleanalytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 5 additions & 3 deletions pkg/usage/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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).
Expand All @@ -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)

}
9 changes: 5 additions & 4 deletions pkg/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/usage/versionset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]}, "-")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/zfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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:
Expand All @@ -217,6 +217,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
Expand Down
6 changes: 3 additions & 3 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)

Expand Down
Loading