diff --git a/integrationtests/smb_test.go b/integrationtests/smb_test.go index ae86a681..501738e7 100644 --- a/integrationtests/smb_test.go +++ b/integrationtests/smb_test.go @@ -20,7 +20,7 @@ import ( smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api" ) -func TestSmb(t *testing.T) { +func TestSMB(t *testing.T) { fsClient, err := fs.New(fsapi.New()) require.Nil(t, err) client, err := smb.New(smbapi.New(), fsClient) @@ -34,14 +34,14 @@ func TestSmb(t *testing.T) { localPath := fmt.Sprintf("C:\\localpath%s", randomString(5)) if err = setupUser(username, password); err != nil { - t.Fatalf("TestSmbAPIGroup %v", err) + t.Fatalf("TestSMBAPIGroup %v", err) } defer removeUser(t, username) - if err = setupSmbShare(smbShare, sharePath, username); err != nil { - t.Fatalf("TestSmbAPIGroup %v", err) + if err = setupSMBShare(smbShare, sharePath, username); err != nil { + t.Fatalf("TestSMBAPIGroup %v", err) } - defer removeSmbShare(t, smbShare) + defer removeSMBShare(t, smbShare) hostname, err := os.Hostname() assert.Nil(t, err) @@ -49,30 +49,30 @@ func TestSmb(t *testing.T) { username = "domain\\" + username remotePath := "\\\\" + hostname + "\\" + smbShare // simulate Mount SMB operations around staging a volume on a node - mountSmbShareReq := &smb.NewSmbGlobalMappingRequest{ + mountSMBShareReq := &smb.NewSMBGlobalMappingRequest{ RemotePath: remotePath, Username: username, Password: password, } - _, err = client.NewSmbGlobalMapping(context.Background(), mountSmbShareReq) + _, err = client.NewSMBGlobalMapping(context.Background(), mountSMBShareReq) if err != nil { - t.Fatalf("TestSmbAPIGroup %v", err) + t.Fatalf("TestSMBAPIGroup %v", err) } - err = getSmbGlobalMapping(remotePath) + err = getSMBGlobalMapping(remotePath) assert.Nil(t, err) err = writeReadFile(remotePath) assert.Nil(t, err) - unmountSmbShareReq := &smb.RemoveSmbGlobalMappingRequest{ + unmountSMBShareReq := &smb.RemoveSMBGlobalMappingRequest{ RemotePath: remotePath, } - _, err = client.RemoveSmbGlobalMapping(context.Background(), unmountSmbShareReq) + _, err = client.RemoveSMBGlobalMapping(context.Background(), unmountSMBShareReq) if err != nil { - t.Fatalf("TestSmbAPIGroup %v", err) + t.Fatalf("TestSMBAPIGroup %v", err) } - err = getSmbGlobalMapping(remotePath) + err = getSMBGlobalMapping(remotePath) assert.NotNil(t, err) err = writeReadFile(localPath) assert.NotNil(t, err) @@ -118,9 +118,9 @@ func removeUser(t *testing.T, username string) { } } -func setupSmbShare(shareName, localPath, username string) error { +func setupSMBShare(shareName, localPath, username string) error { if err := os.MkdirAll(localPath, 0755); err != nil { - return fmt.Errorf("setupSmbShare failed to create local path %q: %v", localPath, err) + return fmt.Errorf("setupSMBShare failed to create local path %q: %v", localPath, err) } cmdLine := fmt.Sprintf(`New-SMBShare -Name $Env:sharename -Path $Env:path -fullaccess $Env:username`) cmd := exec.Command("powershell", "/c", cmdLine) @@ -129,37 +129,37 @@ func setupSmbShare(shareName, localPath, username string) error { fmt.Sprintf("path=%s", localPath), fmt.Sprintf("username=%s", username)) if output, err := cmd.CombinedOutput(); err != nil { - return fmt.Errorf("setupSmbShare failed: %v, output: %q", err, string(output)) + return fmt.Errorf("setupSMBShare failed: %v, output: %q", err, string(output)) } return nil } -func removeSmbShare(t *testing.T, shareName string) { +func removeSMBShare(t *testing.T, shareName string) { cmdLine := fmt.Sprintf(`Remove-SMBShare -Name $Env:sharename -Force`) cmd := exec.Command("powershell", "/c", cmdLine) cmd.Env = append(os.Environ(), fmt.Sprintf("sharename=%s", shareName)) if output, err := cmd.CombinedOutput(); err != nil { - t.Fatalf("setupSmbShare failed: %v, output: %q", err, string(output)) + t.Fatalf("setupSMBShare failed: %v, output: %q", err, string(output)) } return } -func getSmbGlobalMapping(remotePath string) error { +func getSMBGlobalMapping(remotePath string) error { // use PowerShell Environment Variables to store user input string to prevent command line injection // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-5.1 - cmdLine := fmt.Sprintf(`(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath).Status`) + cmdLine := fmt.Sprintf(`(Get-SMBGlobalMapping -RemotePath $Env:smbremotepath).Status`) cmd := exec.Command("powershell", "/c", cmdLine) cmd.Env = append(os.Environ(), fmt.Sprintf("smbremotepath=%s", remotePath)) output, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("Get-SmbGlobalMapping failed: %v, output: %q", err, string(output)) + return fmt.Errorf("Get-SMBGlobalMapping failed: %v, output: %q", err, string(output)) } if !strings.Contains(string(output), "OK") { - return fmt.Errorf("Get-SmbGlobalMapping return status %q instead of OK", string(output)) + return fmt.Errorf("Get-SMBGlobalMapping return status %q instead of OK", string(output)) } return nil } diff --git a/pkg/disk/disk.go b/pkg/disk/disk.go index 76336513..8095e8f4 100644 --- a/pkg/disk/disk.go +++ b/pkg/disk/disk.go @@ -17,13 +17,28 @@ type Interface interface { DiskStats(context.Context, *DiskStatsRequest) (*DiskStatsResponse, error) GetAttachState(context.Context, *GetAttachStateRequest) (*GetAttachStateResponse, error) GetDiskNumberByName(context.Context, *GetDiskNumberByNameRequest) (*GetDiskNumberByNameResponse, error) + // GetDiskState gets the offline/online state of a disk. GetDiskState(context.Context, *GetDiskStateRequest) (*GetDiskStateResponse, error) + + // GetDiskStats returns the stats of a disk (currently it returns the disk size). GetDiskStats(context.Context, *GetDiskStatsRequest) (*GetDiskStatsResponse, error) + + // ListDiskIDs returns a map of DiskID objects where the key is the disk number. ListDiskIDs(context.Context, *ListDiskIDsRequest) (*ListDiskIDsResponse, error) + + // ListDiskLocations returns locations of all + // disk devices enumerated by the host. ListDiskLocations(context.Context, *ListDiskLocationsRequest) (*ListDiskLocationsResponse, error) + + // PartitionDisk initializes and partitions a disk device with the GPT partition style + // (if the disk has not been partitioned already) and returns the resulting volume device ID. PartitionDisk(context.Context, *PartitionDiskRequest) (*PartitionDiskResponse, error) + + // Rescan refreshes the host's storage cache. Rescan(context.Context, *RescanRequest) (*RescanResponse, error) SetAttachState(context.Context, *SetAttachStateRequest) (*SetAttachStateResponse, error) + + // SetDiskState sets the offline/online state of a disk. SetDiskState(context.Context, *SetDiskStateRequest) (*SetDiskStateResponse, error) } diff --git a/pkg/filesystem/filesystem.go b/pkg/filesystem/filesystem.go index fdddec6b..0e9b2e0c 100644 --- a/pkg/filesystem/filesystem.go +++ b/pkg/filesystem/filesystem.go @@ -12,14 +12,31 @@ type Filesystem struct { } type Interface interface { + // CreateSymlink creates a symbolic link called target_path that points to source_path + // in the host filesystem (target_path is the name of the symbolic link created, + // source_path is the existing path). CreateSymlink(context.Context, *CreateSymlinkRequest) (*CreateSymlinkResponse, error) IsMountPoint(context.Context, *IsMountPointRequest) (*IsMountPointResponse, error) + + // IsSymlink checks if a given path is a symlink. IsSymlink(context.Context, *IsSymlinkRequest) (*IsSymlinkResponse, error) LinkPath(context.Context, *LinkPathRequest) (*LinkPathResponse, error) + + // Mkdir creates a directory at the requested path in the host filesystem. Mkdir(context.Context, *MkdirRequest) (*MkdirResponse, error) + + // PathExists checks if the requested path exists in the host filesystem. PathExists(context.Context, *PathExistsRequest) (*PathExistsResponse, error) + + // PathValid checks if the given path is accessible. PathValid(context.Context, *PathValidRequest) (*PathValidResponse, error) + + // Rmdir removes the directory at the requested path in the host filesystem. + // This may be used for unlinking a symlink created through CreateSymlink. Rmdir(context.Context, *RmdirRequest) (*RmdirResponse, error) + + // RmdirContents removes the contents of a directory in the host filesystem. + // Unlike Rmdir it won't delete the requested path, it'll only delete its contents. RmdirContents(context.Context, *RmdirContentsRequest) (*RmdirContentsResponse, error) } @@ -50,7 +67,6 @@ func (f *Filesystem) PathExists(ctx context.Context, request *PathExistsRequest) }, err } -// PathValid checks if the given path is accessible. func (f *Filesystem) PathValid(ctx context.Context, request *PathValidRequest) (*PathValidResponse, error) { klog.V(2).Infof("Request: PathValid with path %q", request.Path) valid, err := f.hostAPI.PathValid(request.Path) diff --git a/pkg/iscsi/iscsi.go b/pkg/iscsi/iscsi.go index d31bd6e5..8b0ba419 100644 --- a/pkg/iscsi/iscsi.go +++ b/pkg/iscsi/iscsi.go @@ -15,13 +15,39 @@ type IsCSI struct { } type Interface interface { + // AddTargetPortal registers an iSCSI target network address for later + // discovery. + // AddTargetPortal currently does not support selecting different NICs or + // a different iSCSI initiator (e.g a hardware initiator). This means that + // Windows will select the initiator NIC and instance on its own. AddTargetPortal(context.Context, *AddTargetPortalRequest) (*AddTargetPortalResponse, error) + + // ConnectTarget connects to an iSCSI Target ConnectTarget(context.Context, *ConnectTargetRequest) (*ConnectTargetResponse, error) + + // DisconnectTarget disconnects from an iSCSI Target DisconnectTarget(context.Context, *DisconnectTargetRequest) (*DisconnectTargetResponse, error) + + // DiscoverTargetPortal initiates discovery on an iSCSI target network address + // and returns discovered IQNs. DiscoverTargetPortal(context.Context, *DiscoverTargetPortalRequest) (*DiscoverTargetPortalResponse, error) + + // GetTargetDisks returns the disk addresses that correspond to an iSCSI + // target GetTargetDisks(context.Context, *GetTargetDisksRequest) (*GetTargetDisksResponse, error) + + // ListTargetPortal lists all currently registered iSCSI target network + // addresses. ListTargetPortals(context.Context, *ListTargetPortalsRequest) (*ListTargetPortalsResponse, error) + + // RemoveTargetPortal removes an iSCSI target network address registration. RemoveTargetPortal(context.Context, *RemoveTargetPortalRequest) (*RemoveTargetPortalResponse, error) + + // SetMutualChapSecret sets the default CHAP secret that all initiators on + // this machine (node) use to authenticate the target on mutual CHAP + // authentication. + // NOTE: This method affects global node state and should only be used + // with consideration to other CSI drivers that run concurrently. SetMutualChapSecret(context.Context, *SetMutualChapSecretRequest) (*SetMutualChapSecretResponse, error) } diff --git a/pkg/smb/api/api.go b/pkg/smb/api/api.go index ce21c40f..fb45fefa 100644 --- a/pkg/smb/api/api.go +++ b/pkg/smb/api/api.go @@ -8,10 +8,10 @@ import ( ) type API interface { - IsSmbMapped(remotePath string) (bool, error) - NewSmbLink(remotePath, localPath string) error - NewSmbGlobalMapping(remotePath, username, password string) error - RemoveSmbGlobalMapping(remotePath string) error + IsSMBMapped(remotePath string) (bool, error) + NewSMBLink(remotePath, localPath string) error + NewSMBGlobalMapping(remotePath, username, password string) error + RemoveSMBGlobalMapping(remotePath string) error } type smbAPI struct{} @@ -22,12 +22,12 @@ func New() API { return smbAPI{} } -func (smbAPI) IsSmbMapped(remotePath string) (bool, error) { +func (smbAPI) IsSMBMapped(remotePath string) (bool, error) { cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status ` cmdEnv := fmt.Sprintf("smbremotepath=%s", remotePath) out, err := utils.RunPowershellCmd(cmdLine, cmdEnv) if err != nil { - return false, fmt.Errorf("error checking smb mapping. cmd %s, output: %s, err: %v", remotePath, string(out), err) + return false, fmt.Errorf("error checking SMB mapping. cmd %s, output: %s, err: %v", remotePath, string(out), err) } if len(out) == 0 || !strings.EqualFold(strings.TrimSpace(string(out)), "OK") { @@ -36,14 +36,14 @@ func (smbAPI) IsSmbMapped(remotePath string) (bool, error) { return true, nil } -// NewSmbLink - creates a directory symbolic link to the remote share. +// NewSMBLink - creates a directory symbolic link to the remote share. // The os.Symlink was having issue for cases where the destination was an SMB share - the container // runtime would complain stating "Access Denied". Because of this, we had to perform // this operation with powershell commandlet creating an directory softlink. // Since os.Symlink is currently being used in working code paths, no attempt is made in // alpha to merge the paths. // TODO (for beta release): Merge the link paths - os.Symlink and Powershell link path. -func (smbAPI) NewSmbLink(remotePath, localPath string) error { +func (smbAPI) NewSMBLink(remotePath, localPath string) error { if !strings.HasSuffix(remotePath, "\\") { // Golang has issues resolving paths mapped to file shares if they do not end in a trailing \ // so add one if needed. @@ -59,7 +59,7 @@ func (smbAPI) NewSmbLink(remotePath, localPath string) error { return nil } -func (smbAPI) NewSmbGlobalMapping(remotePath, username, password string) error { +func (smbAPI) NewSMBGlobalMapping(remotePath, username, password string) error { // use PowerShell Environment Variables to store user input string to prevent command line injection // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-5.1 cmdLine := fmt.Sprintf(`$PWord = ConvertTo-SecureString -String $Env:smbpassword -AsPlainText -Force` + @@ -69,15 +69,15 @@ func (smbAPI) NewSmbGlobalMapping(remotePath, username, password string) error { if output, err := utils.RunPowershellCmd(cmdLine, fmt.Sprintf("smbuser=%s", username), fmt.Sprintf("smbpassword=%s", password), fmt.Sprintf("smbremotepath=%s", remotePath)); err != nil { - return fmt.Errorf("NewSmbGlobalMapping failed. output: %q, err: %v", string(output), err) + return fmt.Errorf("NewSMBGlobalMapping failed. output: %q, err: %v", string(output), err) } return nil } -func (smbAPI) RemoveSmbGlobalMapping(remotePath string) error { +func (smbAPI) RemoveSMBGlobalMapping(remotePath string) error { cmd := `Remove-SmbGlobalMapping -RemotePath $Env:smbremotepath -Force` if output, err := utils.RunPowershellCmd(cmd, fmt.Sprintf("smbremotepath=%s", remotePath)); err != nil { - return fmt.Errorf("UnmountSmbShare failed. output: %q, err: %v", string(output), err) + return fmt.Errorf("UnmountSMBShare failed. output: %q, err: %v", string(output), err) } return nil } diff --git a/pkg/smb/smb.go b/pkg/smb/smb.go index 4ac2ff5d..4a25e32f 100644 --- a/pkg/smb/smb.go +++ b/pkg/smb/smb.go @@ -10,18 +10,21 @@ import ( "k8s.io/klog/v2" ) -type Smb struct { +type SMB struct { hostAPI smbapi.API fs fs.Interface } type Interface interface { - NewSmbGlobalMapping(context.Context, *NewSmbGlobalMappingRequest) (*NewSmbGlobalMappingResponse, error) - RemoveSmbGlobalMapping(context.Context, *RemoveSmbGlobalMappingRequest) (*RemoveSmbGlobalMappingResponse, error) + // NewSMBGlobalMapping creates an SMB mapping on the SMB client to an SMB share. + NewSMBGlobalMapping(context.Context, *NewSMBGlobalMappingRequest) (*NewSMBGlobalMappingResponse, error) + + // RemoveSMBGlobalMapping removes the SMB mapping to an SMB share. + RemoveSMBGlobalMapping(context.Context, *RemoveSMBGlobalMappingRequest) (*RemoveSMBGlobalMappingResponse, error) } -// check that Smb implements the Interface -var _ Interface = &Smb{} +// check that SMB implements the Interface +var _ Interface = &SMB{} func normalizeWindowsPath(path string) string { normalizedPath := strings.Replace(path, "/", "\\", -1) @@ -43,21 +46,21 @@ func getRootMappingPath(path string) (string, error) { klog.Errorf("remote path (%s) is invalid", path) return "", fmt.Errorf("remote path (%s) is invalid", path) } - // parts[0] is a smb host name - // parts[1] is a smb share name + // parts[0] is a SMB host name + // parts[1] is a SMB share name return strings.ToLower("\\\\" + parts[0] + "\\" + parts[1]), nil } -func New(hostAPI smbapi.API, fsClient fs.Interface) (*Smb, error) { - return &Smb{ +func New(hostAPI smbapi.API, fsClient fs.Interface) (*SMB, error) { + return &SMB{ hostAPI: hostAPI, fs: fsClient, }, nil } -func (s *Smb) NewSmbGlobalMapping(context context.Context, request *NewSmbGlobalMappingRequest) (*NewSmbGlobalMappingResponse, error) { - klog.V(2).Infof("calling NewSmbGlobalMapping with remote path %q", request.RemotePath) - response := &NewSmbGlobalMappingResponse{} +func (s *SMB) NewSMBGlobalMapping(context context.Context, request *NewSMBGlobalMappingRequest) (*NewSMBGlobalMappingResponse, error) { + klog.V(2).Infof("calling NewSMBGlobalMapping with remote path %q", request.RemotePath) + response := &NewSMBGlobalMappingResponse{} remotePath := normalizeWindowsPath(request.RemotePath) localPath := request.LocalPath @@ -71,7 +74,7 @@ func (s *Smb) NewSmbGlobalMapping(context context.Context, request *NewSmbGlobal return response, err } - isMapped, err := s.hostAPI.IsSmbMapped(mappingPath) + isMapped, err := s.hostAPI.IsSMBMapped(mappingPath) if err != nil { isMapped = false } @@ -86,9 +89,9 @@ func (s *Smb) NewSmbGlobalMapping(context context.Context, request *NewSmbGlobal if !validResp.Valid { klog.V(4).Infof("RemotePath %s is not valid, removing now", mappingPath) - err := s.hostAPI.RemoveSmbGlobalMapping(mappingPath) + err := s.hostAPI.RemoveSMBGlobalMapping(mappingPath) if err != nil { - klog.Errorf("RemoveSmbGlobalMapping(%s) failed with %v", mappingPath, err) + klog.Errorf("RemoveSMBGlobalMapping(%s) failed with %v", mappingPath, err) return response, err } isMapped = false @@ -99,9 +102,9 @@ func (s *Smb) NewSmbGlobalMapping(context context.Context, request *NewSmbGlobal if !isMapped { klog.V(4).Infof("Remote %s not mapped. Mapping now!", mappingPath) - err = s.hostAPI.NewSmbGlobalMapping(mappingPath, request.Username, request.Password) + err = s.hostAPI.NewSMBGlobalMapping(mappingPath, request.Username, request.Password) if err != nil { - klog.Errorf("failed NewSmbGlobalMapping %v", err) + klog.Errorf("failed NewSMBGlobalMapping %v", err) return response, err } } @@ -113,20 +116,20 @@ func (s *Smb) NewSmbGlobalMapping(context context.Context, request *NewSmbGlobal klog.Errorf("failed validate plugin path %v", err) return response, err } - err = s.hostAPI.NewSmbLink(remotePath, localPath) + err = s.hostAPI.NewSMBLink(remotePath, localPath) if err != nil { - klog.Errorf("failed NewSmbLink %v", err) + klog.Errorf("failed NewSMBLink %v", err) return response, fmt.Errorf("creating link %s to %s failed with error: %v", localPath, remotePath, err) } } - klog.V(2).Infof("NewSmbGlobalMapping on remote path %q is completed", request.RemotePath) + klog.V(2).Infof("NewSMBGlobalMapping on remote path %q is completed", request.RemotePath) return response, nil } -func (s *Smb) RemoveSmbGlobalMapping(context context.Context, request *RemoveSmbGlobalMappingRequest) (*RemoveSmbGlobalMappingResponse, error) { - klog.V(2).Infof("calling RemoveSmbGlobalMapping with remote path %q", request.RemotePath) - response := &RemoveSmbGlobalMappingResponse{} +func (s *SMB) RemoveSMBGlobalMapping(context context.Context, request *RemoveSMBGlobalMappingRequest) (*RemoveSMBGlobalMappingResponse, error) { + klog.V(2).Infof("calling RemoveSMBGlobalMapping with remote path %q", request.RemotePath) + response := &RemoveSMBGlobalMappingResponse{} remotePath := normalizeWindowsPath(request.RemotePath) if remotePath == "" { @@ -139,12 +142,12 @@ func (s *Smb) RemoveSmbGlobalMapping(context context.Context, request *RemoveSmb return response, err } - err = s.hostAPI.RemoveSmbGlobalMapping(mappingPath) + err = s.hostAPI.RemoveSMBGlobalMapping(mappingPath) if err != nil { - klog.Errorf("failed RemoveSmbGlobalMapping %v", err) + klog.Errorf("failed RemoveSMBGlobalMapping %v", err) return response, err } - klog.V(2).Infof("RemoveSmbGlobalMapping on remote path %q is completed", request.RemotePath) + klog.V(2).Infof("RemoveSMBGlobalMapping on remote path %q is completed", request.RemotePath) return response, nil } diff --git a/pkg/smb/smb_test.go b/pkg/smb/smb_test.go index 03fe635f..64ad7225 100644 --- a/pkg/smb/smb_test.go +++ b/pkg/smb/smb_test.go @@ -9,23 +9,23 @@ import ( smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api" ) -type fakeSmbAPI struct{} +type fakeSMBAPI struct{} -var _ smbapi.API = &fakeSmbAPI{} +var _ smbapi.API = &fakeSMBAPI{} -func (fakeSmbAPI) NewSmbGlobalMapping(remotePath, username, password string) error { +func (fakeSMBAPI) NewSMBGlobalMapping(remotePath, username, password string) error { return nil } -func (fakeSmbAPI) RemoveSmbGlobalMapping(remotePath string) error { +func (fakeSMBAPI) RemoveSMBGlobalMapping(remotePath string) error { return nil } -func (fakeSmbAPI) IsSmbMapped(remotePath string) (bool, error) { +func (fakeSMBAPI) IsSMBMapped(remotePath string) (bool, error) { return false, nil } -func (fakeSmbAPI) NewSmbLink(remotePath, localPath string) error { +func (fakeSMBAPI) NewSMBLink(remotePath, localPath string) error { return nil } @@ -56,7 +56,7 @@ func (fakeFileSystemAPI) IsSymlink(path string) (bool, error) { return true, nil } -func TestNewSmbGlobalMapping(t *testing.T) { +func TestNewSMBGlobalMapping(t *testing.T) { testCases := []struct { remote string local string @@ -82,23 +82,23 @@ func TestNewSmbGlobalMapping(t *testing.T) { t.Fatalf("FileSystem client could not be initialized for testing: %v", err) } - client, err := New(&fakeSmbAPI{}, fsClient) + client, err := New(&fakeSMBAPI{}, fsClient) if err != nil { - t.Fatalf("Smb client could not be initialized for testing: %v", err) + t.Fatalf("SMB client could not be initialized for testing: %v", err) } for _, tc := range testCases { - req := &NewSmbGlobalMappingRequest{ + req := &NewSMBGlobalMappingRequest{ LocalPath: tc.local, RemotePath: tc.remote, Username: tc.username, Password: tc.password, } - _, err := client.NewSmbGlobalMapping(context.TODO(), req) + _, err := client.NewSMBGlobalMapping(context.TODO(), req) if tc.expectError && err == nil { - t.Errorf("Expected error but NewSmbGlobalMapping returned a nil error") + t.Errorf("Expected error but NewSMBGlobalMapping returned a nil error") } if !tc.expectError && err != nil { - t.Errorf("Expected no errors but NewSmbGlobalMapping returned error: %v", err) + t.Errorf("Expected no errors but NewSMBGlobalMapping returned error: %v", err) } } } diff --git a/pkg/smb/types.go b/pkg/smb/types.go index d38ab64a..318ee9c6 100644 --- a/pkg/smb/types.go +++ b/pkg/smb/types.go @@ -1,20 +1,20 @@ package smb -type NewSmbGlobalMappingRequest struct { +type NewSMBGlobalMappingRequest struct { RemotePath string LocalPath string Username string Password string } -type NewSmbGlobalMappingResponse struct { +type NewSMBGlobalMappingResponse struct { // Intentionally empty. } -type RemoveSmbGlobalMappingRequest struct { +type RemoveSMBGlobalMappingRequest struct { RemotePath string } -type RemoveSmbGlobalMappingResponse struct { +type RemoveSMBGlobalMappingResponse struct { // Intentionally empty. } diff --git a/pkg/system/system.go b/pkg/system/system.go index 8e08e122..88bfc817 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -12,9 +12,20 @@ type System struct { } type Interface interface { + // GetBIOSSerialNumber returns the device's serial number GetBIOSSerialNumber(context.Context, *GetBIOSSerialNumberRequest) (*GetBIOSSerialNumberResponse, error) + + // GetService queries a Windows service state GetService(context.Context, *GetServiceRequest) (*GetServiceResponse, error) + + // StartService starts a Windows service + // NOTE: This method affects global node state and should only be used + // with consideration to other CSI drivers that run concurrently. StartService(context.Context, *StartServiceRequest) (*StartServiceResponse, error) + + // StopService stops a Windows service + // NOTE: This method affects global node state and should only be used + // with consideration to other CSI drivers that run concurrently. StopService(context.Context, *StopServiceRequest) (*StopServiceResponse, error) } diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index 03d14164..5733f510 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -15,19 +15,43 @@ type Volume struct { type Interface interface { DismountVolume(context.Context, *DismountVolumeRequest) (*DismountVolumeResponse, error) + // FormatVolume formats a volume with NTFS. FormatVolume(context.Context, *FormatVolumeRequest) (*FormatVolumeResponse, error) + + // GetClosestVolumeIDFromTargetPath gets the closest volume id for a given target path + // by following symlinks and moving up in the filesystem, if after moving up in the filesystem + // we get to a DriveLetter then the volume corresponding to this drive letter is returned instead. GetClosestVolumeIDFromTargetPath(context.Context, *GetClosestVolumeIDFromTargetPathRequest) (*GetClosestVolumeIDFromTargetPathResponse, error) + + // GetDiskNumberFromVolumeID gets the disk number of the disk where the volume is located. GetDiskNumberFromVolumeID(context.Context, *GetDiskNumberFromVolumeIDRequest) (*GetDiskNumberFromVolumeIDResponse, error) GetVolumeDiskNumber(context.Context, *VolumeDiskNumberRequest) (*VolumeDiskNumberResponse, error) GetVolumeIDFromMount(context.Context, *VolumeIDFromMountRequest) (*VolumeIDFromMountResponse, error) + + // GetVolumeIDFromTargetPath gets the volume id for a given target path. GetVolumeIDFromTargetPath(context.Context, *GetVolumeIDFromTargetPathRequest) (*GetVolumeIDFromTargetPathResponse, error) + + // GetVolumeStats gathers total bytes and used bytes for a volume. GetVolumeStats(context.Context, *GetVolumeStatsRequest) (*GetVolumeStatsResponse, error) + + // IsVolumeFormatted checks if a volume is formatted. IsVolumeFormatted(context.Context, *IsVolumeFormattedRequest) (*IsVolumeFormattedResponse, error) + + // ListVolumesOnDisk returns the volume IDs (in \\.\Volume{GUID} format) for all volumes from a + // given disk number and partition number (optional) ListVolumesOnDisk(context.Context, *ListVolumesOnDiskRequest) (*ListVolumesOnDiskResponse, error) + + // MountVolume mounts the volume at the requested global staging path. MountVolume(context.Context, *MountVolumeRequest) (*MountVolumeResponse, error) + + // ResizeVolume performs resizing of the partition and file system for a block based volume. ResizeVolume(context.Context, *ResizeVolumeRequest) (*ResizeVolumeResponse, error) + + // UnmountVolume flushes data cache to disk and removes the global staging path. UnmountVolume(context.Context, *UnmountVolumeRequest) (*UnmountVolumeResponse, error) VolumeStats(context.Context, *VolumeStatsRequest) (*VolumeStatsResponse, error) + + // WriteVolumeCache write volume cache to disk. WriteVolumeCache(context.Context, *WriteVolumeCacheRequest) (*WriteVolumeCacheResponse, error) }