Skip to content

Commit

Permalink
Merge pull request #80 from YeYoot/master
Browse files Browse the repository at this point in the history
V3.0.1
  • Loading branch information
YeYoot authored Aug 14, 2022
2 parents b94cc42 + e6c9fca commit 34a1d68
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 23 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

[Releases](https://github.com/Huawei/eSDK_K8S_Plugin/releases)

## Changes since v3.0.0

**Fixes**

- Optimization secretGenerate tool

**Enhancements**

- support configure the permission for attaching volumes


## Changes since v2.2.16

**Enhancements**
Expand Down
27 changes: 20 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# usage: make -f Makefile VER=3.0.0 PLATFORM=X86 RELEASE_VER=2.5.RC2

# [3.0.0]
VER=VER
# [X86 ARM]
PLATFORM=PLATFORM
# eSDK Version: [2.5.RC1 2.5.RC2 ...]
RELEASE_VER=RELEASE_VER
VER=VER

export GO111MODULE=on
export GOPATH:=$(GOPATH):$(shell pwd)
export PACKAGE=eSDK_Enterprise_Storage_${RELEASE_VER}_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
export CLOUD_PACKAGE=eSDK_Cloud_Storage_${RELEASE_VER}_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
ifeq (${RELEASE_VER}, RELEASE_VER)
export PACKAGE=eSDK_Enterprise_Storage_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
export CLOUD_PACKAGE=eSDK_Cloud_Storage_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
else
export PACKAGE=eSDK_Enterprise_Storage_${RELEASE_VER}_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
export CLOUD_PACKAGE=eSDK_Cloud_Storage_${RELEASE_VER}_Kubernetes_CSI_Plugin_V${VER}_${PLATFORM}_64
endif


all:COMMON_1 DIFF COMMON_2
all:PREPARE BUILD COPY_FILE PACK

COMMON_1:
PREPARE:
rm -rf ./${PACKAGE} ./${CLOUD_PACKAGE}
rm -rf ./src/vendor
mkdir -p ./${PACKAGE}/bin

DIFF:
BUILD:
ifeq (${PLATFORM}, X86)
go build -o ./${PACKAGE}/bin/huawei-csi ./csi
go build -o ./${PACKAGE}/bin/secretGenerate ./tools/secretGenerate
Expand All @@ -26,7 +38,7 @@ ifeq (${PLATFORM}, ARM)
GOOS=linux GOARCH=arm64 go build -o ./${PACKAGE}/bin/secretUpdate ./tools/secretUpdate
endif

COMMON_2:
COPY_FILE:
mkdir -p ./${PACKAGE}/deploy
cp -r ./deploy/huawei-csi-node.yaml ./deploy/huawei-csi-rbac.yaml ./deploy/huawei-csi-configmap ./${PACKAGE}/deploy
cp ./deploy/huawei-csi-controller-snapshot-v1.yaml ./${PACKAGE}/deploy/huawei-csi-controller.yaml
Expand All @@ -41,6 +53,7 @@ COMMON_2:
mkdir -p ./${PACKAGE}/tools
cp -r ./tools/imageUpload/* ./${PACKAGE}/tools

PACK:
zip -r ${PACKAGE}.zip ./${PACKAGE}
mv ${PACKAGE} ${CLOUD_PACKAGE}
zip -r ${CLOUD_PACKAGE}.zip ./${CLOUD_PACKAGE}
Expand Down
3 changes: 3 additions & 0 deletions csi/backend/plugin/fusionstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (p *FusionStoragePlugin) getParams(name string,
"authClient",
"storageQuota",
"accountName",
"fsPermission",
"allSquash",
"rootSquash",
}

for _, key := range paramKeys {
Expand Down
3 changes: 3 additions & 0 deletions csi/backend/plugin/oceanstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func (p *OceanstorPlugin) getParams(ctx context.Context,
"sourceVolumeName",
"snapshotParentId",
"applicationType",
"fsPermission",
"allSquash",
"rootSquash",
}

for _, key := range paramKeys {
Expand Down
30 changes: 29 additions & 1 deletion csi/backend/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
import (
"context"
"errors"
"regexp"

"github.com/container-storage-interface/spec/lib/go/csi"

Expand Down Expand Up @@ -160,7 +161,34 @@ func (p *basePlugin) lunStageVolume(ctx context.Context,
"accessMode": parameters["accessMode"].(csi.VolumeCapability_AccessMode_Mode),
}

return p.stageVolume(ctx, connectInfo)
err := p.stageVolume(ctx, connectInfo)
if err != nil {
return err
}

chmodFsPermission(ctx, parameters)
return nil
}

func chmodFsPermission(ctx context.Context, parameters map[string]interface{}) {
fsPermission, exist := parameters["fsPermission"].(string)
if !exist || fsPermission == "" {
log.AddContext(ctx).Infoln("Global mount directory permission dose not need to be modified.")
return
}
reg := regexp.MustCompile(`^\d\d\d$`)
match := reg.FindStringSubmatch(fsPermission)
if match == nil {
log.AddContext(ctx).Errorf("fsPermission [%s] in storageClass.yaml format must be \"^\\d\\d\\d$\". "+
"Chmod targetPath: [%v] fsPermission failed.", fsPermission, parameters["targetPath"])
return
}

_, err := utils.ExecShellCmd(ctx, "chmod %v %v", fsPermission, parameters["targetPath"])
if err != nil {
log.AddContext(ctx).Errorf("Failed to modify the directory permission. "+
"targetPath: [%v], fsPermission: [%s]", parameters["targetPath"], fsPermission)
}
}

func (p *basePlugin) lunConnectVolume(ctx context.Context,
Expand Down
5 changes: 3 additions & 2 deletions csi/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func (d *Driver) getCreatedVolume(ctx context.Context,

volName := vol.GetVolumeName()
attributes := map[string]string{
"backend": pool.Parent,
"name": volName,
"backend": pool.Parent,
"name": volName,
"fsPermission": req.Parameters["fsPermission"],
}

if lunWWN, err := vol.GetLunWWN(); err == nil {
Expand Down
1 change: 1 addition & 0 deletions csi/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
parameters["fsType"] = mnt.GetFsType()
parameters["mountFlags"] = strings.Join(opts, ",")
parameters["accessMode"] = volumeAccessMode
parameters["fsPermission"] = req.VolumeContext["fsPermission"]
default:
msg := fmt.Sprintf("Invalid volume capability.")
log.AddContext(ctx).Errorln(msg)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion helm/esdk/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type: application
version: 1.0.0

# compatible Kubernetes versions, helm installation fails fail if the cluster runs an unsupported Kubernetes version
kubeVersion: ">= 1.21.0 < 1.25.0"
kubeVersion: ">= 1.19.0 < 1.25.0"
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
8 changes: 6 additions & 2 deletions storage/fusionstorage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,10 @@ func (cli *Client) CreateFileSystem(ctx context.Context, params map[string]inter
data["forbidden_dpc"] = notForbidden
}

if params["fspermission"] != nil && params["fspermission"] != "" {
data["unix_permission"] = params["fspermission"]
}

resp, err := cli.post(ctx, "/api/v2/converged_service/namespaces", data)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1302,8 +1306,8 @@ func (cli *Client) AllowNfsShareAccess(ctx context.Context, params map[string]in
"share_id": params["shareid"].(string),
"access_value": params["accessval"].(int),
"sync": 0,
"all_squash": 1,
"root_squash": 1,
"all_squash": params["allsquash"].(int),
"root_squash": params["rootsquash"].(int),
"type": 0,
"account_id": params["accountid"].(string),
}
Expand Down
35 changes: 30 additions & 5 deletions storage/fusionstorage/volume/nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ func (p *NAS) preCreate(ctx context.Context, params map[string]interface{}) erro
}
}

// all_squash root_squash
params["allsquash"], exist = params["allsquash"].(string)
if !exist || params["allsquash"] == "" {
params["allsquash"] = 1
} else {
allSquash, err := strconv.Atoi(params["allsquash"].(string))
if err != nil {
return utils.Errorf(ctx, "parameter allSquash [%v] in sc needs to be a number.", params["allsquash"])
}
params["allsquash"] = allSquash
}

params["rootsquash"], exist = params["rootsquash"].(string)
if !exist || params["rootsquash"] == "" {
params["rootsquash"] = 1
} else {
rootSquash, err := strconv.Atoi(params["rootsquash"].(string))
if err != nil {
return utils.Errorf(ctx, "parameter rootSquash [%v] in sc needs to be a number.", params["rootsquash"])
}
params["rootsquash"] = rootSquash
}

return nil
}

Expand Down Expand Up @@ -303,7 +326,7 @@ func (p *NAS) createShare(ctx context.Context,
}
}
return map[string]interface{}{
"shareID": share["id"].(string),
"shareID": share["id"].(string),
"accountId": accountId,
}, nil
}
Expand Down Expand Up @@ -345,10 +368,12 @@ func (p *NAS) deleteShare(ctx context.Context, shareID, accountId string) error
func (p *NAS) allowShareAccess(ctx context.Context,
params, taskResult map[string]interface{}) (map[string]interface{}, error) {
createParams := map[string]interface{}{
"name": params["authclient"].(string),
"shareid": taskResult["shareID"].(string),
"accessval": 1,
"accountid": params["accountid"].(string),
"name": params["authclient"].(string),
"shareid": taskResult["shareID"].(string),
"accessval": 1,
"accountid": params["accountid"].(string),
"allsquash": params["allsquash"].(int),
"rootsquash": params["rootsquash"].(int),
}

err := p.cli.AllowNfsShareAccess(ctx, createParams)
Expand Down
10 changes: 7 additions & 3 deletions storage/oceanstor/client/file_system_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (cli *Client) CreateFileSystem(ctx context.Context,
"ISSHOWSNAPDIR": false,
}

if params["fspermission"] != nil && params["fspermission"] != "" {
data["unixPermissions"] = params["fspermission"]
}

if hyperMetro, hyperMetroOK := params["hypermetro"].(bool); hyperMetroOK && hyperMetro {
data["fileSystemMode"] = hyperMetroFilesystem
if vstoreId, exist := params["vstoreId"].(string); exist && vstoreId != "" {
Expand Down Expand Up @@ -81,17 +85,17 @@ func (cli *Client) CreateFileSystem(ctx context.Context,
func dealCreateFSError(ctx context.Context, code int64) error {
suggestMsg := "Suggestion: delete current PVC and specify the proper capacity of the file system and try again."
if code == exceedFSCapacityUpper {
return utils.Errorf(ctx,"create filesystem error. ErrorCode: %d. Reason: the entered capacity is " +
return utils.Errorf(ctx, "create filesystem error. ErrorCode: %d. Reason: the entered capacity is "+
"greater than the maximum capacity of the file system. %s", code, suggestMsg)
}

if code == lessFSCapacityLower {
return utils.Errorf(ctx,"create filesystem error. ErrorCode: %d. Reason: the entered capacity is " +
return utils.Errorf(ctx, "create filesystem error. ErrorCode: %d. Reason: the entered capacity is "+
"less than the minimum capacity of the file system. %s", code, suggestMsg)
}

if code != 0 {
return utils.Errorf(ctx,"Create filesystem error. ErrorCode: %d. Please contact technical " +
return utils.Errorf(ctx, "Create filesystem error. ErrorCode: %d. Please contact technical "+
"support.", code)
}

Expand Down
27 changes: 25 additions & 2 deletions storage/oceanstor/volume/nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,29 @@ func (p *NAS) allowShareAccess(ctx context.Context,
return nil, err
}

var allSquash int
var exist bool
params["allsquash"], exist = params["allsquash"].(string)
if !exist || params["allsquash"] == "" {
allSquash = 1
} else {
allSquash, err = strconv.Atoi(params["allsquash"].(string))
if err != nil {
return nil, utils.Errorf(ctx, "parameter allSquash [%v] in sc needs to be a number.", params["allsquash"])
}
}

var rootSquash int
params["rootsquash"], exist = params["rootsquash"].(string)
if !exist || params["rootsquash"] == "" {
rootSquash = 1
} else {
rootSquash, err = strconv.Atoi(params["rootsquash"].(string))
if err != nil {
return nil, utils.Errorf(ctx, "parameter rootSquash [%v] in sc needs to be a number.", params["allsquash"])
}
}

for _, i := range strings.Split(authClient, ";") {
_, exist := accesses[i]
delete(accesses, i)
Expand All @@ -549,8 +572,8 @@ func (p *NAS) allowShareAccess(ctx context.Context,
"PARENTID": shareID,
"ACCESSVAL": 1,
"SYNC": 0,
"ALLSQUASH": 1,
"ROOTSQUASH": 1,
"ALLSQUASH": allSquash,
"ROOTSQUASH": rootSquash,
}
if vStoreID != "" {
params["vstoreId"] = vStoreID
Expand Down

0 comments on commit 34a1d68

Please sign in to comment.