Skip to content

Commit

Permalink
Various corrections in the iscsi pkg
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 95236d5 commit 45dc3aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 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

0 comments on commit 45dc3aa

Please sign in to comment.