Skip to content

Commit

Permalink
fix(controller): revert fail on publish volume when host doesn't exists
Browse files Browse the repository at this point in the history
This reverts commit 07203cb.
  • Loading branch information
paullaffitte committed Oct 1, 2020
1 parent deecec5 commit 33fbc15
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions pkg/controller/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
Expand All @@ -15,22 +14,6 @@ import (
"k8s.io/klog"
)

func (driver *Driver) showHosts(hostName string) (interface{}, error) {
data, _, err := driver.dothillClient.Request("/show/hosts/")

if err != nil {
return nil, err
}

for _, object := range data.Objects {
if object.Name == "hosts" && object.PropertiesMap["host-id"].Data == hostName {
return object, nil
}
}

return nil, errors.New("host not found")
}

// ControllerPublishVolume attaches the given volume to the node
func (driver *Driver) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
if len(req.GetVolumeId()) == 0 {
Expand All @@ -53,11 +36,7 @@ func (driver *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Cont
}

initiatorName := req.GetNodeId()
_, err = driver.showHosts(initiatorName)
if err != nil {
return nil, status.Error(codes.NotFound, fmt.Sprintf("cannot map volume, reason: \"%v\"", err.Error()))
}
klog.Infof("attach request for initiator %s, volume id: %s", initiatorName, req.GetVolumeId())
klog.Infof("attach request for initiator %s, volume id : %s", initiatorName, req.GetVolumeId())

lun, err := driver.chooseLUN()
if err != nil {
Expand Down Expand Up @@ -125,7 +104,7 @@ func (driver *Driver) chooseLUN() (int, error) {
sort.Sort(Volumes(volumes))
index := 1
for ; index < len(volumes); index++ {
if volumes[index].LUN-volumes[index-1].LUN > 1 {
if volumes[index].LUN - volumes[index-1].LUN > 1 {
return volumes[index-1].LUN + 1, nil
}
}
Expand All @@ -134,7 +113,7 @@ func (driver *Driver) chooseLUN() (int, error) {
return 1, nil
}

if volumes[len(volumes)-1].LUN+1 < common.MaximumLUN {
if volumes[len(volumes)-1].LUN + 1 < common.MaximumLUN {
return volumes[len(volumes)-1].LUN + 1, nil
}

Expand Down

0 comments on commit 33fbc15

Please sign in to comment.