From 76f905aa8e7bd63557f6efe1c9eea6887bd175f9 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Tue, 21 Dec 2021 16:26:41 +0530 Subject: [PATCH] various linter corrections and code cleanup Signed-off-by: Humble Chirammal --- pkg/iscsi/driver.go | 24 +++++------ pkg/iscsi/identityserver.go | 1 + pkg/iscsi/iscsi.go | 7 +++- pkg/iscsi/iscsi_util.go | 7 ++-- pkg/iscsi/nodeserver.go | 2 + pkg/lib/iscsi/iscsi/iscsi.go | 41 +++++++++---------- .../csi-lib-iscsi/iscsi/iscsi.go | 41 +++++++++---------- 7 files changed, 63 insertions(+), 60 deletions(-) diff --git a/pkg/iscsi/driver.go b/pkg/iscsi/driver.go index 46095217..7d8b1b4b 100644 --- a/pkg/iscsi/driver.go +++ b/pkg/iscsi/driver.go @@ -18,31 +18,27 @@ package iscsi import ( "fmt" + "os" + "github.com/container-storage-interface/spec/lib/go/csi" "k8s.io/klog/v2" - "os" ) type driver struct { - name string - nodeID string - version string - + name string + nodeID string + version string endpoint string - - ns *nodeServer - - cap []*csi.VolumeCapability_AccessMode - cscap []*csi.ControllerServiceCapability + ns *nodeServer + cap []*csi.VolumeCapability_AccessMode + cscap []*csi.ControllerServiceCapability } const ( driverName = "iscsi.csi.k8s.io" ) -var ( - version = "0.1.0" -) +var version = "0.1.0" func NewDriver(nodeID, endpoint string) *driver { klog.Infof("Driver: %v version: %v", driverName, version) @@ -54,7 +50,7 @@ func NewDriver(nodeID, endpoint string) *driver { endpoint: endpoint, } - if err := os.MkdirAll(fmt.Sprintf("/var/run/%s", driverName), 0755); err != nil { + if err := os.MkdirAll(fmt.Sprintf("/var/run/%s", driverName), 0o755); err != nil { panic(err) } d.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER}) diff --git a/pkg/iscsi/identityserver.go b/pkg/iscsi/identityserver.go index 5ca54df6..800b5c2a 100644 --- a/pkg/iscsi/identityserver.go +++ b/pkg/iscsi/identityserver.go @@ -51,6 +51,7 @@ func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) { klog.V(5).Infof("Using default capabilities") + return &csi.GetPluginCapabilitiesResponse{ Capabilities: []*csi.PluginCapability{ { diff --git a/pkg/iscsi/iscsi.go b/pkg/iscsi/iscsi.go index ed239750..25893eca 100644 --- a/pkg/iscsi/iscsi.go +++ b/pkg/iscsi/iscsi.go @@ -94,7 +94,8 @@ func getISCSIInfo(req *csi.NodePublishVolumeRequest) (*iscsiDisk, error) { secret: secret, sessionSecret: sessionSecret, discoverySecret: discoverySecret, - InitiatorName: initiatorName} + InitiatorName: initiatorName, + } return iscsiDisk, nil } @@ -136,6 +137,7 @@ func getISCSIDiskMounter(iscsiInfo *iscsiDisk, req *csi.NodePublishVolumeRequest deviceUtil: util.NewDeviceHandler(util.NewIOHandler()), connector: buildISCSIConnector(iscsiInfo), } + return diskMounter } @@ -153,6 +155,7 @@ func portalMounter(portal string) string { if !strings.Contains(portal, ":") { portal += ":3260" } + return portal } @@ -161,6 +164,7 @@ func parseSecret(secretParams string) map[string]string { if err := json.Unmarshal([]byte(secretParams), &secret); err != nil { return nil } + return secret } @@ -211,6 +215,7 @@ func parseDiscoverySecret(secretParams map[string]string) (iscsiLib.Secrets, err } secret.SecretsType = "chap" + return secret, nil } diff --git a/pkg/iscsi/iscsi_util.go b/pkg/iscsi/iscsi_util.go index a129e918..9b15a4f5 100644 --- a/pkg/iscsi/iscsi_util.go +++ b/pkg/iscsi/iscsi_util.go @@ -18,11 +18,12 @@ package iscsi import ( "fmt" + "os" + iscsiLib "github.com/kubernetes-csi/csi-lib-iscsi/iscsi" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/klog/v2" - "os" "k8s.io/utils/mount" ) @@ -48,7 +49,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) { return "", nil } - if err := os.MkdirAll(mntPath, 0750); err != nil { + if err := os.MkdirAll(mntPath, 0o750); err != nil { klog.Errorf("iscsi: failed to mkdir %s, error", mntPath) return "", err } @@ -130,10 +131,10 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, targetPath string) error klog.Info("successfully detached ISCSI device") return nil - } func getIscsiInfoPath(volumeID string) string { runPath := fmt.Sprintf("/var/run/%s", driverName) + return fmt.Sprintf("%s/iscsi-%s.json", runPath, volumeID) } diff --git a/pkg/iscsi/nodeserver.go b/pkg/iscsi/nodeserver.go index 288a02ef..97090e7f 100644 --- a/pkg/iscsi/nodeserver.go +++ b/pkg/iscsi/nodeserver.go @@ -48,6 +48,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis if _, err := util.AttachDisk(*diskMounter); err != nil { return nil, status.Error(codes.Internal, err.Error()) } + return &csi.NodePublishVolumeResponse{}, nil } @@ -66,6 +67,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu if err := iscsiutil.DetachDisk(*diskUnmounter, targetPath); err != nil { return nil, status.Error(codes.Internal, err.Error()) } + return &csi.NodeUnpublishVolumeResponse{}, nil } diff --git a/pkg/lib/iscsi/iscsi/iscsi.go b/pkg/lib/iscsi/iscsi/iscsi.go index 465ca0bd..ce81184a 100644 --- a/pkg/lib/iscsi/iscsi/iscsi.go +++ b/pkg/lib/iscsi/iscsi/iscsi.go @@ -41,7 +41,7 @@ type iscsiSession struct { type deviceInfo []Device -// Device contains informations about a device +// Device contains information about a device type Device struct { Name string `json:"name"` Hctl string `json:"hctl"` @@ -58,28 +58,26 @@ type HCTL struct { LUN int } -// Connector provides a struct to hold all of the needed parameters to make our iSCSI connection +// Connector provides a struct to hold all the needed parameters to make our iSCSI connection type Connector struct { - VolumeName string `json:"volume_name"` - TargetIqn string `json:"target_iqn"` - TargetPortals []string `json:"target_portal"` - Lun int32 `json:"lun"` - AuthType string `json:"auth_type"` - DiscoverySecrets Secrets `json:"discovery_secrets"` - SessionSecrets Secrets `json:"session_secrets"` - Interface string `json:"interface"` - + VolumeName string `json:"volume_name"` + TargetIqn string `json:"target_iqn"` + TargetPortals []string `json:"target_portal"` + Lun int32 `json:"lun"` + AuthType string `json:"auth_type"` + DiscoverySecrets Secrets `json:"discovery_secrets"` + SessionSecrets Secrets `json:"session_secrets"` + Interface string `json:"interface"` MountTargetDevice *Device `json:"mount_target_device"` Devices []Device `json:"devices"` - - RetryCount uint `json:"retry_count"` - CheckInterval uint `json:"check_interval"` - DoDiscovery bool `json:"do_discovery"` - DoCHAPDiscovery bool `json:"do_chap_discovery"` + RetryCount uint `json:"retry_count"` + CheckInterval uint `json:"check_interval"` + DoDiscovery bool `json:"do_discovery"` + DoCHAPDiscovery bool `json:"do_chap_discovery"` } func init() { - // by default we don't log anything, EnableDebugLogging() can turn on some tracing + // by default, we don't log anything, EnableDebugLogging() can turn on some tracing debug = log.New(ioutil.Discard, "", 0) } @@ -89,7 +87,7 @@ func EnableDebugLogging(writer io.Writer) { debug = log.New(writer, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile) } -// parseSession takes the raw stdout from the iscsiadm -m session command and encodes it into an iSCSI session type +// parseSession takes the raw stdout from the `iscsiadm -m session` command and encodes it into an iSCSI session type func parseSessions(lines string) []iscsiSession { entries := strings.Split(strings.TrimSpace(lines), "\n") r := strings.NewReplacer("[", "", @@ -115,6 +113,7 @@ func parseSessions(lines string) []iscsiSession { } sessions = append(sessions, s) } + return sessions } @@ -322,7 +321,7 @@ func (c *Connector) connectTarget(targetIqn string, target string, iFace string, if _, err := iscsiCmd(append(baseArgs, []string{"-R"}...)...); err != nil { debug.Printf("Failed to rescan session, err: %v", err) if os.IsTimeout(err) { - debug.Printf("iscsiadm timeouted, logging out") + debug.Printf("iscsiadm timeout, logging out") cmd := execCommand("iscsiadm", append(baseArgs, []string{"-u"}...)...) out, err := cmd.CombinedOutput() if err != nil { @@ -404,7 +403,7 @@ func Disconnect(targetIqn string, targets []string) { } // Disconnect performs a disconnect operation from an appliance. -// Be sure to disconnect all deivces properly before doing this as it can result in data loss. +// Be sure to disconnect all devices properly before doing this as it can result in data loss. func (c *Connector) Disconnect() { Disconnect(c.TargetIqn, c.TargetPortals) } @@ -795,7 +794,7 @@ func (d *Device) Delete() error { return d.WriteDeviceFile("delete", "1") } -// Rescan rescan an SCSI device by writing 1 in /sys/class/scsi_device/h:c:t:l/device/rescan +// Rescan does a rescan of SCSI device by writing 1 in /sys/class/scsi_device/h:c:t:l/device/rescan func (d *Device) Rescan() error { return d.WriteDeviceFile("rescan", "1") } diff --git a/vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go b/vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go index 465ca0bd..ce81184a 100644 --- a/vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go +++ b/vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go @@ -41,7 +41,7 @@ type iscsiSession struct { type deviceInfo []Device -// Device contains informations about a device +// Device contains information about a device type Device struct { Name string `json:"name"` Hctl string `json:"hctl"` @@ -58,28 +58,26 @@ type HCTL struct { LUN int } -// Connector provides a struct to hold all of the needed parameters to make our iSCSI connection +// Connector provides a struct to hold all the needed parameters to make our iSCSI connection type Connector struct { - VolumeName string `json:"volume_name"` - TargetIqn string `json:"target_iqn"` - TargetPortals []string `json:"target_portal"` - Lun int32 `json:"lun"` - AuthType string `json:"auth_type"` - DiscoverySecrets Secrets `json:"discovery_secrets"` - SessionSecrets Secrets `json:"session_secrets"` - Interface string `json:"interface"` - + VolumeName string `json:"volume_name"` + TargetIqn string `json:"target_iqn"` + TargetPortals []string `json:"target_portal"` + Lun int32 `json:"lun"` + AuthType string `json:"auth_type"` + DiscoverySecrets Secrets `json:"discovery_secrets"` + SessionSecrets Secrets `json:"session_secrets"` + Interface string `json:"interface"` MountTargetDevice *Device `json:"mount_target_device"` Devices []Device `json:"devices"` - - RetryCount uint `json:"retry_count"` - CheckInterval uint `json:"check_interval"` - DoDiscovery bool `json:"do_discovery"` - DoCHAPDiscovery bool `json:"do_chap_discovery"` + RetryCount uint `json:"retry_count"` + CheckInterval uint `json:"check_interval"` + DoDiscovery bool `json:"do_discovery"` + DoCHAPDiscovery bool `json:"do_chap_discovery"` } func init() { - // by default we don't log anything, EnableDebugLogging() can turn on some tracing + // by default, we don't log anything, EnableDebugLogging() can turn on some tracing debug = log.New(ioutil.Discard, "", 0) } @@ -89,7 +87,7 @@ func EnableDebugLogging(writer io.Writer) { debug = log.New(writer, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile) } -// parseSession takes the raw stdout from the iscsiadm -m session command and encodes it into an iSCSI session type +// parseSession takes the raw stdout from the `iscsiadm -m session` command and encodes it into an iSCSI session type func parseSessions(lines string) []iscsiSession { entries := strings.Split(strings.TrimSpace(lines), "\n") r := strings.NewReplacer("[", "", @@ -115,6 +113,7 @@ func parseSessions(lines string) []iscsiSession { } sessions = append(sessions, s) } + return sessions } @@ -322,7 +321,7 @@ func (c *Connector) connectTarget(targetIqn string, target string, iFace string, if _, err := iscsiCmd(append(baseArgs, []string{"-R"}...)...); err != nil { debug.Printf("Failed to rescan session, err: %v", err) if os.IsTimeout(err) { - debug.Printf("iscsiadm timeouted, logging out") + debug.Printf("iscsiadm timeout, logging out") cmd := execCommand("iscsiadm", append(baseArgs, []string{"-u"}...)...) out, err := cmd.CombinedOutput() if err != nil { @@ -404,7 +403,7 @@ func Disconnect(targetIqn string, targets []string) { } // Disconnect performs a disconnect operation from an appliance. -// Be sure to disconnect all deivces properly before doing this as it can result in data loss. +// Be sure to disconnect all devices properly before doing this as it can result in data loss. func (c *Connector) Disconnect() { Disconnect(c.TargetIqn, c.TargetPortals) } @@ -795,7 +794,7 @@ func (d *Device) Delete() error { return d.WriteDeviceFile("delete", "1") } -// Rescan rescan an SCSI device by writing 1 in /sys/class/scsi_device/h:c:t:l/device/rescan +// Rescan does a rescan of SCSI device by writing 1 in /sys/class/scsi_device/h:c:t:l/device/rescan func (d *Device) Rescan() error { return d.WriteDeviceFile("rescan", "1") }