Skip to content

Commit

Permalink
Merge pull request #94 from David-T-White/feat/apiv2-update
Browse files Browse the repository at this point in the history
Merge exos-x-api-go lib version 2 compatibility changes
  • Loading branch information
David-T-White committed Oct 13, 2023
2 parents 46331ea + bb2a524 commit 04df2ca
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 338 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif
ifdef VERSION
VERSION := $(VERSION)
else
VERSION := v1.7.3
VERSION := v1.8.0
endif
HELM_VERSION := $(subst v,,$(VERSION))
VERSION_FLAG = -X $(GITHUB_URL)/pkg/common.Version=$(VERSION)
Expand Down
31 changes: 17 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,43 @@ go 1.19
require (
github.com/Seagate/csi-lib-iscsi v1.0.3
github.com/Seagate/csi-lib-sas v1.0.2
github.com/Seagate/seagate-exos-x-api-go v1.0.11
github.com/container-storage-interface/spec v1.4.0
github.com/golang/protobuf v1.5.2
github.com/Seagate/seagate-exos-x-api-go v1.0.18
github.com/container-storage-interface/spec v1.8.0
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/kubernetes-csi/csi-test v0.0.0-20191016154743-6931aedb3df0
github.com/onsi/gomega v1.10.5
github.com/onsi/gomega v1.27.6
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.13.0
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/grpc v1.50.0
k8s.io/klog/v2 v2.80.1
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
k8s.io/klog/v2 v2.100.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/namsral/flag v1.7.4-pre // indirect
github.com/nxadm/tail v1.4.4 // indirect
github.com/onsi/ginkgo v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/Seagate/seagate-exos-x-api-go => ../seagate-exos-x-api-go
//replace github.com/Seagate/seagate-exos-x-api-go => ./seagate-exos-x-api-go
// replace github.com/Seagate/csi-lib-iscsi => ../csi-lib-iscsi
// replace github.com/Seagate/csi-lib-sas => ../csi-lib-sas
259 changes: 36 additions & 223 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion helm/csi-charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ image:
repository: ghcr.io/seagate/seagate-exos-x-csi
# -- Tag to use for nodes and controller
# @default -- Uses Chart.appVersion value by default if tag does not specify a new version.
tag: "v1.7.3"
tag: "v1.8.0"
# -- Default is set to IfNotPresent, to override use Always here to always pull the specified version
pullPolicy: Always
# -- Controller sidecar for provisioning
Expand Down
36 changes: 17 additions & 19 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"syscall"

storageapi "github.com/Seagate/seagate-exos-x-api-go"
storageapi "github.com/Seagate/seagate-exos-x-api-go/pkg/v1"
"github.com/Seagate/seagate-exos-x-csi/pkg/common"
"github.com/Seagate/seagate-exos-x-csi/pkg/node_service"
pb "github.com/Seagate/seagate-exos-x-csi/pkg/node_service/node_servicepb"
Expand All @@ -20,16 +20,16 @@ import (
"k8s.io/klog/v2"
)

const (
snapshotNotFoundErrorCode = -10050
hostMapDoesNotExistsErrorCode = -10074
volumeNotFoundErrorCode = -10075
volumeHasSnapshot = -10183
snapshotAlreadyExists = -10186
initiatorNicknameOrIdentifierNotFound = -10386
unmapFailedErrorCode = -10509
invalidArgumentErrorCode = -10058
)
var volumeCapabilities = []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
}

var csiMutexes = map[string]*sync.Mutex{
"/csi.v1.Controller/CreateVolume": {},
Expand Down Expand Up @@ -226,7 +226,7 @@ func (controller *Controller) beginRoutine(ctx *DriverCtx, methodName string) er
}

func (controller *Controller) endRoutine() {
controller.client.HTTPClient.CloseIdleConnections()
controller.client.CloseConnections()
}

func (controller *Controller) configureClient(credentials map[string]string) error {
Expand All @@ -246,15 +246,13 @@ func (controller *Controller) configureClient(credentials map[string]string) err
return status.Error(codes.InvalidArgument, fmt.Sprintf("(%s) is missing from secrets", common.APIAddressConfigKey))
}

klog.Infof("using API at address (%s)", apiAddr)
klog.InfoS("using API", "address", apiAddr)
if controller.client.SessionValid(apiAddr, username) {
return nil
}

controller.client.Username = username
controller.client.Password = password
controller.client.Addr = apiAddr
klog.Infof("login to API address %q as user %q", controller.client.Addr, controller.client.Username)
klog.InfoS("login to API", "address", apiAddr, "username", username)
controller.client.StoreCredentials(apiAddr, "", username, password)
err := controller.client.Login()
if err != nil {
return status.Error(codes.Unauthenticated, err.Error())
Expand Down Expand Up @@ -341,7 +339,7 @@ func (controller *Controller) GetNodeInitiators(ctx context.Context, nodeAddress
return initiators, err
}

func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress string, volumeName string) error {
func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress string, volumeWWN string) error {
clientConnection := controller.nodeServiceClients[nodeAddress]
if clientConnection == nil {
klog.V(3).InfoS("node grpc client not found, establishing...", "nodeAddress", nodeAddress)
Expand All @@ -352,7 +350,7 @@ func (controller *Controller) NotifyUnmap(ctx context.Context, nodeAddress strin
}
controller.nodeServiceClients[nodeAddress] = clientConnection
}
return node_service.NotifyUnmap(ctx, clientConnection, volumeName)
return node_service.NotifyUnmap(ctx, clientConnection, volumeWWN)
}

// Graceful shutdown of Node-Controller RPC Clients
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"context"
"fmt"
"strconv"

"github.com/Seagate/seagate-exos-x-csi/pkg/common"
"github.com/container-storage-interface/spec/lib/go/csi"
Expand All @@ -30,21 +29,21 @@ func (controller *Controller) ControllerExpandVolume(ctx context.Context, req *c
var expansionSize int64
if err != nil {
return nil, err
} else if volume, ok := response.ObjectsMap["volume"]; !ok {
} else if len(response) == 0 {
return nil, fmt.Errorf("volume %q not found", volumeName)
} else if sizeNumeric, ok := volume.PropertiesMap["size-numeric"]; !ok {
} else if response[0].SizeNumeric == 0 {
return nil, fmt.Errorf("could not get current volume size, thus volume expansion is not possible")
} else if currentBlocks, err := strconv.ParseInt(sizeNumeric.Data, 10, 32); err != nil {
} else if response[0].Blocks == 0 {
return nil, fmt.Errorf("could not parse volume size: %v", err)
} else {
currentSize := currentBlocks * 512
currentSize := response[0].Blocks * response[0].BlockSize
klog.V(2).Infof("current size: %d bytes", currentSize)
expansionSize = newSize - currentSize
klog.V(2).Infof("expanding volume by %d bytes", expansionSize)
}

expansionSizeStr := getSizeStr(expansionSize)
if _, _, err := controller.client.ExpandVolume(volumeName, expansionSizeStr); err != nil {
if _, err := controller.client.ExpandVolume(volumeName, expansionSizeStr); err != nil {
return nil, err
}

Expand Down
32 changes: 22 additions & 10 deletions pkg/controller/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"strings"

storageapitypes "github.com/Seagate/seagate-exos-x-api-go/pkg/common"
storageapi "github.com/Seagate/seagate-exos-x-api-go/pkg/v1"

"github.com/Seagate/seagate-exos-x-csi/pkg/common"
"github.com/Seagate/seagate-exos-x-csi/pkg/storage"
"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -72,7 +75,7 @@ func (controller *Controller) CreateVolume(ctx context.Context, req *csi.CreateV
size := req.GetCapacityRange().GetRequiredBytes()
sizeStr := getSizeStr(size)
pool := parameters[common.PoolConfigKey]
poolType, _ := controller.client.Info.GetPoolType(pool)
poolType, _ := controller.client.GetPoolType(pool)
wwn := ""

if len(poolType) == 0 {
Expand Down Expand Up @@ -104,40 +107,49 @@ func (controller *Controller) CreateVolume(ctx context.Context, req *csi.CreateV
if err != nil {
return nil, err
}
_, apistatus, err2 := controller.client.CopyVolume(sourceName, volumeName, parameters[common.PoolConfigKey])
apistatus, err2 := controller.client.CopyVolume(sourceName, volumeName, parameters[common.PoolConfigKey])
if err2 != nil {
klog.Infof("-- CopyVolume apistatus.ReturnCode %v", apistatus.ReturnCode)
if apistatus != nil && apistatus.ReturnCode == snapshotNotFoundErrorCode {
if apistatus != nil && apistatus.ReturnCode == storageapitypes.SnapshotNotFoundErrorCode {
return nil, status.Errorf(codes.NotFound, "Snapshot source (%s) not found", sourceId)
} else {
return nil, err2
}
}

} else {
_, _, err2 := controller.client.CreateVolume(volumeName, sizeStr, parameters[common.PoolConfigKey], poolType)
volume, _, err2 := controller.client.CreateVolume(volumeName, sizeStr, parameters[common.PoolConfigKey], poolType)
if err2 != nil {
return nil, err
}
if volume != nil {
wwn = volume.Wwn
}
}
}
if wwn == "" {
wwn, err = controller.client.GetVolumeWwn(volumeName)
}
if err != nil {
klog.ErrorS(err, "Error retrieving WWN of new volume", "volumeName", volumeName)
return nil, err
}

if storageProtocol == common.StorageProtocolISCSI {
// Fill iSCSI context parameters
targetId, err1 := controller.client.Info.GetTargetId("iSCSI")
targetId, err1 := storageapi.GetTargetId(controller.client.Info, "iSCSI")
if err1 != nil {
klog.Errorf("++ GetTargetId error: %v", err1)
}
req.GetParameters()["iqn"] = targetId
portals, err2 := controller.client.Info.GetPortals()
portals, err2 := controller.client.GetPortals()
if err2 != nil {
klog.Errorf("++ GetPortals error: %v", err2)
}
req.GetParameters()["portals"] = portals
klog.V(2).Infof("Storing iSCSI iqn: %s, portals: %v", targetId, portals)
}

wwn, _ = controller.client.GetVolumeWwn(volumeName)
volumeId := common.VolumeIdAugment(volumeName, storageProtocol, wwn)

volume := &csi.CreateVolumeResponse{
Expand All @@ -164,13 +176,13 @@ func (controller *Controller) DeleteVolume(ctx context.Context, req *csi.DeleteV
volumeName, _ := common.VolumeIdGetName(req.GetVolumeId())
klog.Infof("deleting volume %s", volumeName)

_, respStatus, err := controller.client.DeleteVolume(volumeName)
respStatus, err := controller.client.DeleteVolume(volumeName)
if err != nil {
if respStatus != nil {
if respStatus.ReturnCode == volumeNotFoundErrorCode {
if respStatus.ReturnCode == storageapitypes.VolumeNotFoundErrorCode {
klog.Infof("volume %s does not exist, assuming it has already been deleted", volumeName)
return &csi.DeleteVolumeResponse{}, nil
} else if respStatus.ReturnCode == volumeHasSnapshot {
} else if respStatus.ReturnCode == storageapitypes.VolumeHasSnapshot {
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("volume %s cannot be deleted since it has snapshots", volumeName))
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

storageapitypes "github.com/Seagate/seagate-exos-x-api-go/pkg/common"

"github.com/Seagate/seagate-exos-x-csi/pkg/common"
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -54,6 +56,7 @@ func (driver *Controller) ControllerUnpublishVolume(ctx context.Context, req *cs
}

volumeName, _ := common.VolumeIdGetName(req.GetVolumeId())
volumeWWN, _ := common.VolumeIdGetWwn(req.GetVolumeId())
nodeIP := req.GetNodeId()
storageProtocol, err := common.VolumeIdGetStorageProtocol(req.GetVolumeId())
if err != nil {
Expand All @@ -68,15 +71,15 @@ func (driver *Controller) ControllerUnpublishVolume(ctx context.Context, req *cs

klog.InfoS("unmapping volume from initiator", "volumeName", volumeName, "initiators", initiators)
for _, initiator := range initiators {
_, status, err := driver.client.UnmapVolume(volumeName, initiator)
status, err := driver.client.UnmapVolume(volumeName, initiator)
if err != nil {
if status != nil && status.ReturnCode == unmapFailedErrorCode {
if status != nil && status.ReturnCode == storageapitypes.UnmapFailedErrorCode {
klog.Info("unmap failed, assuming volume is already unmapped")
} else {
klog.Errorf("unknown error while unmapping initiator %s: %v", initiator, err)
}
} else {
driver.NotifyUnmap(ctx, nodeIP, volumeName)
driver.NotifyUnmap(ctx, nodeIP, volumeWWN)
}
}

Expand Down
Loading

0 comments on commit 04df2ca

Please sign in to comment.