Skip to content

Commit

Permalink
Squashed 'pkg/lib/iscsi/' changes from 5c802c4..366f319
Browse files Browse the repository at this point in the history
366f319 Merge pull request kubernetes-csi#35 from humblec/rel-alpha1
83b78f5 Merge pull request kubernetes-csi#36 from humblec/owners
56f04a2 make sure the mountTargetDevice in the connector is non nil
83dec6e update OWNERS file

git-subtree-dir: pkg/lib/iscsi
git-subtree-split: 366f319
  • Loading branch information
humblec committed Sep 2, 2022
1 parent 3d20e84 commit 67e5053
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
12 changes: 10 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md

approvers:
- saad-ali
- humblec
- j-griffith
reviews:
- jsafrane
- msau42
- saad-ali
- xing-yang
reviewers:
- humblec
- j-griffith
- jsafrane
- msau42
- saad-ali
- xing-yang
19 changes: 15 additions & 4 deletions iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ func (c *Connector) Connect() (string, error) {
c.MountTargetDevice = mountTargetDevice
if err != nil {
debug.Printf("Connect failed: %v", err)
RemoveSCSIDevices(c.Devices...)
err := RemoveSCSIDevices(c.Devices...)
if err != nil {
return "", err
}
c.MountTargetDevice = nil
c.Devices = []Device{}
return "", err
Expand Down Expand Up @@ -392,15 +395,21 @@ func (c *Connector) discoverTarget(targetIqn string, iFace string, portal string
func Disconnect(targetIqn string, targets []string) {
for _, target := range targets {
targetPortal := strings.Split(target, ":")[0]
Logout(targetIqn, targetPortal)
err := Logout(targetIqn, targetPortal)
if err != nil {
return
}
}

deleted := map[string]bool{}
if _, ok := deleted[targetIqn]; ok {
return
}
deleted[targetIqn] = true
DeleteDBEntry(targetIqn)
err := DeleteDBEntry(targetIqn)
if err != nil {
return
}
}

// Disconnect performs a disconnect operation from an appliance.
Expand Down Expand Up @@ -669,7 +678,9 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
for _, device := range c.Devices {
devicePaths = append(devicePaths, device.GetPath())
}

if c.MountTargetDevice == nil {
return nil, fmt.Errorf("mountTargetDevice in the connector is nil")
}
if devices, err := GetSCSIDevices([]string{c.MountTargetDevice.GetPath()}, false); err != nil {
return nil, err
} else {
Expand Down
10 changes: 8 additions & 2 deletions iscsi/iscsiadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ func CreateDBEntry(tgtIQN, portal, iFace string, discoverySecrets, sessionSecret

if discoverySecrets.SecretsType == "chap" {
debug.Printf("Setting CHAP Discovery...")
createCHAPEntries(baseArgs, discoverySecrets, true)
err := createCHAPEntries(baseArgs, discoverySecrets, true)
if err != nil {
return err
}
}

if sessionSecrets.SecretsType == "chap" {
debug.Printf("Setting CHAP Session...")
createCHAPEntries(baseArgs, sessionSecrets, false)
err := createCHAPEntries(baseArgs, sessionSecrets, false)
if err != nil {
return err
}
}

return err
Expand Down
14 changes: 4 additions & 10 deletions iscsi/multipath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ package iscsi

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"time"
)

type pathGroup struct {
Paths []path `json:"paths"`
}

type path struct {
Device string `json:"dev"`
}

// ExecWithTimeout execute a command with a timeout and returns an error if timeout is excedeed
func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]byte, error) {
debug.Printf("Executing command '%v' with args: '%v'.\n", command, args)
Expand All @@ -35,13 +28,14 @@ func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]by
// We want to check the context error to see if the timeout was executed.
// The error returned by cmd.Output() will be OS specific based on what
// happens when a process is killed.
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
debug.Printf("Command '%s' timeout reached.\n", command)
return nil, ctx.Err()
}

if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
var ee *exec.ExitError
if ok := errors.Is(err, ee); ok {
debug.Printf("Non-zero exit code: %s\n", err)
err = fmt.Errorf("%s", ee.Stderr)
}
Expand Down

0 comments on commit 67e5053

Please sign in to comment.