mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-11 22:10:11 +01:00
chore(go-lint): fix golint warning (#133)
Fixes several go lint cases reported by go report. Signed-off-by: wiwen <shenggxhz@gmail.com>
This commit is contained in:
parent
639ead416e
commit
f5ae3ff476
25 changed files with 78 additions and 51 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ tags
|
|||
*.swp
|
||||
*.swo
|
||||
*.swn
|
||||
*.idea
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
3
pkg/common/env/env.go
vendored
3
pkg/common/env/env.go
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -76,9 +76,9 @@ type NonBlockingGRPCServer interface {
|
|||
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}
|
||||
idntyServer: ids,
|
||||
ctrlServer: cs,
|
||||
agentServer: ns}
|
||||
}
|
||||
|
||||
// NonBlocking server
|
||||
|
|
@ -88,9 +88,9 @@ type nonBlockingGRPCServer struct {
|
|||
wg sync.WaitGroup
|
||||
server *grpc.Server
|
||||
endpoint string
|
||||
idnty_server csi.IdentityServer
|
||||
ctrl_server csi.ControllerServer
|
||||
agent_server csi.NodeServer
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 the application name
|
||||
AppName string = "OpenEBS"
|
||||
|
||||
// Event labels
|
||||
// RunningStatus status is running
|
||||
RunningStatus string = "running"
|
||||
// Event labels
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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]}, "-")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue