Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ var rootCmd = &cobra.Command{
func driverStart() error {
log.Infof("CSI Options = {%s, %s, %s}", csiNodeID, csiEndpoint, csiClientInfoPath)

dsmService := service.NewDsmService()

// 1. Login DSMs by given ClientInfo
info, err := common.LoadConfig(csiClientInfoPath)
if err != nil {
log.Errorf("Failed to read config: %v", err)
return err
}


dsmService := service.NewDsmService(info.SkipLunPrefix, info.SkipSharePrefix)

for _, client := range info.Clients {
err := dsmService.AddDsm(client)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volName, volCap := req.GetName(), req.GetVolumeCapabilities()
volContentSrc := req.GetVolumeContentSource()

// Check if use_pvc_name is true, and if so, use the pvc name as the volume name
usePvcName, _ := strconv.ParseBool(req.GetParameters()[models.CSIUsePVCName])
if usePvcName {
volName = req.GetParameters()[models.CSIPVCName]
}

var srcSnapshotId string = ""
var srcVolumeId string = ""
var multiSession bool = false
Expand Down Expand Up @@ -172,9 +178,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
spec := &models.CreateK8sVolumeSpec{
DsmIp: params["dsm"],
K8sVolumeName: volName,
LunName: models.GenLunName(volName),
LunName: cs.dsmService.GenLunName(volName),
LunDescription: lunDescription,
ShareName: models.GenShareName(volName),
ShareName: cs.dsmService.GenShareName(volName),
Location: params["location"],
Size: sizeInByte,
Type: params["type"],
Expand Down
4 changes: 3 additions & 1 deletion pkg/dsm/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type ClientInfo struct {
}

type SynoInfo struct {
Clients []ClientInfo `yaml:"clients"`
Clients []ClientInfo `yaml:"clients"`
SkipLunPrefix bool `yaml:"skip_lun_prefix"`
SkipSharePrefix bool `yaml:"skip_share_prefix"`
}

func LoadConfig(configPath string) (*SynoInfo, error) {
Expand Down
43 changes: 34 additions & 9 deletions pkg/dsm/service/dsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ package service
import (
"errors"
"fmt"

"github.com/cenkalti/backoff/v4"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"strconv"
"time"
"strings"
"time"

"github.com/SynologyOpenSource/synology-csi/pkg/dsm/common"
"github.com/SynologyOpenSource/synology-csi/pkg/dsm/webapi"
"github.com/SynologyOpenSource/synology-csi/pkg/models"
"github.com/SynologyOpenSource/synology-csi/pkg/utils"
"github.com/cenkalti/backoff/v4"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type DsmService struct {
dsms map[string]*webapi.DSM

skipLunPrefix bool
skipSharePrefix bool
}

func NewDsmService() *DsmService {
func NewDsmService(skipLunPrefix bool, skipSharePrefix bool) *DsmService {
return &DsmService{
dsms: make(map[string]*webapi.DSM),

skipLunPrefix: skipLunPrefix,
skipSharePrefix: skipSharePrefix,
}
}

Expand Down Expand Up @@ -637,11 +643,30 @@ func (service *DsmService) GetVolume(volId string) *models.K8sVolumeRespSpec {
return nil
}

func (service *DsmService) GenLunName(volName string) string {
if service.skipLunPrefix {
return volName
}
return fmt.Sprintf("%s-%s", models.LunPrefix, volName)
}

func (service *DsmService) GenShareName(volName string) string {
log.Infof("GenShareName: %s, skipSharePrefix: %v", volName, service.skipSharePrefix)
shareName := volName
if !service.skipSharePrefix {
shareName = fmt.Sprintf("%s-%s", models.SharePrefix, volName)
}
if len(shareName) > models.MaxShareLen {
return shareName[:models.MaxShareLen]
}
return shareName
}

func (service *DsmService) GetVolumeByName(volName string) *models.K8sVolumeRespSpec {
volumes := service.ListVolumes()
for _, volume := range volumes {
if volume.Name == models.GenLunName(volName) ||
volume.Name == models.GenShareName(volName) {
if volume.Name == service.GenLunName(volName) ||
volume.Name == service.GenShareName(volName) {
return volume
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/interfaces/IDsmService.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ type IDsmService interface {
ListSnapshots(volId string) []*models.K8sSnapshotRespSpec
GetVolumeByName(volName string) *models.K8sVolumeRespSpec
GetSnapshotByName(snapshotName string) *models.K8sSnapshotRespSpec
}
GenLunName(volName string) string
GenShareName(volName string) string
}
20 changes: 4 additions & 16 deletions pkg/models/dsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

package models

import (
"fmt"
)

const (
K8sCsiName = "Kubernetes CSI"

Expand Down Expand Up @@ -33,16 +29,8 @@ const (
IqnPrefix = "iqn.2000-01.com.synology:"
SharePrefix = "k8s-csi"
ShareSnapshotDescPrefix = "(Do not change)"
)

func GenLunName(volName string) string {
return fmt.Sprintf("%s-%s", LunPrefix, volName)
}

func GenShareName(volName string) string {
shareName := fmt.Sprintf("%s-%s", SharePrefix, volName)
if len(shareName) > MaxShareLen {
return shareName[:MaxShareLen]
}
return shareName
}
// CSI parameter definitions
CSIPVCName = "csi.storage.k8s.io/pvc/name"
CSIUsePVCName = "use_pvc_name"
)