Skip to content

Commit

Permalink
temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
boddumanohar committed May 10, 2021
1 parent ea011ad commit 895dc15
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
44 changes: 24 additions & 20 deletions pkg/smb/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}

// check if create SubDir is enable in storage class parameters
parameters := req.GetParameters()
var createSubDir string
for k, v := range parameters {
switch strings.ToLower(k) {
case createSubDirField:
createSubDir = v
}
// parameters := req.GetParameters()
// var createSubDir string
// for k, v := range parameters {
// switch strings.ToLower(k) {
// case createSubDirField:
// createSubDir = v
// }
// }

// if strings.EqualFold(createSubDir, "true") {
// Mount smb base share so we can create a subdirectory
if err := d.internalMount(ctx, smbVol, volCap); err != nil {
return nil, status.Errorf(codes.Internal, "failed to mount smb server: %v", err.Error())
}

if strings.EqualFold(createSubDir, "true") {
// Mount smb base share so we can create a subdirectory
if err := d.internalMount(ctx, smbVol, volCap); err != nil {
return nil, status.Errorf(codes.Internal, "failed to mount smb server: %v", err.Error())
defer func() {
if err = d.internalUnmount(ctx, smbVol); err != nil {
klog.Warningf("failed to unmount smb server: %v", err.Error())
}
defer func() {
if err = d.internalUnmount(ctx, smbVol); err != nil {
klog.Warningf("failed to unmount smb server: %v", err.Error())
}
}()
}
}()
// }

// Create subdirectory under base-dir
// TODO: revisit permissions
Expand Down Expand Up @@ -181,7 +181,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
}

// Given a smbVolume, return a CSI volume id
func (d *Driver) getVolumeIDFromNfsVol(vol *smbVolume) string {
func (d *Driver) getVolumeIDFromSmbVol(vol *smbVolume) string {
idElements := make([]string, totalIDElements)
idElements[idsourceField] = strings.Trim(vol.sourceField, "/")
idElements[idBaseDir] = strings.Trim(vol.baseDir, "/")
Expand Down Expand Up @@ -214,6 +214,10 @@ func (d *Driver) internalMount(ctx context.Context, vol *smbVolume, volCap *csi.
},
VolumeCapability: volCap,
VolumeId: vol.id,
Secrets: map[string]string{
"username": "username",
"password": "password",
},
})
return err
}
Expand Down Expand Up @@ -264,7 +268,7 @@ func (d *Driver) newSMBVolume(name string, size int64, params map[string]string)
subDir: name,
size: size,
}
vol.id = d.getVolumeIDFromNfsVol(vol)
vol.id = d.getVolumeIDFromSmbVol(vol)

return vol, nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/smb/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
defer d.volumeLocks.Release(volumeID)

var username, password, domain string
// username = "a"
// password = "b"
for k, v := range secrets {
switch strings.ToLower(k) {
case usernameField:
Expand All @@ -202,6 +204,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
return nil, status.Error(codes.Internal, fmt.Sprintf("MkdirAll %s failed with error: %v", targetPath, err))
}
sensitiveMountOptions = []string{fmt.Sprintf("%s=%s,%s=%s", usernameField, username, passwordField, password)}
klog.V(2).Infof("sensitive mount options %v", sensitiveMountOptions)
mountOptions = mountFlags
if domain != "" {
mountOptions = append(mountOptions, fmt.Sprintf("%s=%s", domainField, domain))
Expand Down
6 changes: 3 additions & 3 deletions test/integration/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ if [[ "${ARCH}" == "x86_64" || ${ARCH} == "unknown" ]]; then
fi

# Run CSI driver as a background service
_output/${ARCH}/smbplugin --endpoint "$endpoint" --nodeid CSINode -v=5 &
# _output/${ARCH}/smbplugin --endpoint "$endpoint" --nodeid CSINode -v=5 &
trap cleanup EXIT

sleep 5
# set secret for csc node stage
export X_CSI_SECRETS=username=username,"password=test"
params='source="//0.0.0.0",createSubDir="true",share=share'
export X_CSI_SECRETS="username=username","password=test"
params='source="//127.0.0.1/share",createSubDir="true",share=share'
# Begin to run CSI functions one by one
echo 'Create volume test:'
readonly value=$("$CSC_BIN" controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes 2147483648 --params "$params")
Expand Down

0 comments on commit 895dc15

Please sign in to comment.