Skip to content

Commit

Permalink
various linter corrections and code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Dec 21, 2021
1 parent ea65b19 commit 76f905a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 60 deletions.
24 changes: 10 additions & 14 deletions pkg/iscsi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down
1 change: 1 addition & 0 deletions pkg/iscsi/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
7 changes: 6 additions & 1 deletion pkg/iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func getISCSIInfo(req *csi.NodePublishVolumeRequest) (*iscsiDisk, error) {
secret: secret,
sessionSecret: sessionSecret,
discoverySecret: discoverySecret,
InitiatorName: initiatorName}
InitiatorName: initiatorName,
}

return iscsiDisk, nil
}
Expand Down Expand Up @@ -136,6 +137,7 @@ func getISCSIDiskMounter(iscsiInfo *iscsiDisk, req *csi.NodePublishVolumeRequest
deviceUtil: util.NewDeviceHandler(util.NewIOHandler()),
connector: buildISCSIConnector(iscsiInfo),
}

return diskMounter
}

Expand All @@ -153,6 +155,7 @@ func portalMounter(portal string) string {
if !strings.Contains(portal, ":") {
portal += ":3260"
}

return portal
}

Expand All @@ -161,6 +164,7 @@ func parseSecret(secretParams string) map[string]string {
if err := json.Unmarshal([]byte(secretParams), &secret); err != nil {
return nil
}

return secret
}

Expand Down Expand Up @@ -211,6 +215,7 @@ func parseDiscoverySecret(secretParams map[string]string) (iscsiLib.Secrets, err
}

secret.SecretsType = "chap"

return secret, nil
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/iscsi/iscsi_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions pkg/iscsi/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
41 changes: 20 additions & 21 deletions pkg/lib/iscsi/iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
}

Expand All @@ -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("[", "",
Expand All @@ -115,6 +113,7 @@ func parseSessions(lines string) []iscsiSession {
}
sessions = append(sessions, s)
}

return sessions
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
41 changes: 20 additions & 21 deletions vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 76f905a

Please sign in to comment.