From 0a2b8ff7851ae7d2eab1e9a45742fff7250b669c Mon Sep 17 00:00:00 2001 From: Alexander Ding Date: Wed, 19 Oct 2022 19:38:59 +0000 Subject: [PATCH] refactor: rename API to HostAPI --- integrationtests/disk_test.go | 2 +- integrationtests/filesystem_test.go | 2 +- integrationtests/iscsi_test.go | 6 +++--- integrationtests/smb_test.go | 4 ++-- integrationtests/system_test.go | 2 +- integrationtests/volume_test.go | 4 ++-- pkg/disk/disk.go | 6 +++--- pkg/disk/{api/api.go => hostapi/hostapi.go} | 6 +++--- pkg/disk/{api => hostapi}/types.go | 0 pkg/filesystem/filesystem.go | 6 +++--- pkg/filesystem/filesystem_test.go | 4 ++-- .../{api/api_test.go => hostapi/hostapi_test.go} | 0 pkg/filesystem/{api/api.go => hostapi/hotsapi.go} | 10 +++++----- pkg/iscsi/{api/api.go => hostapi/hostapi.go} | 8 ++++---- pkg/iscsi/{api => hostapi}/types.go | 0 pkg/iscsi/iscsi.go | 6 +++--- pkg/smb/{api/api.go => hostapi/hostapi.go} | 6 +++--- pkg/smb/smb.go | 6 +++--- pkg/smb/smb_test.go | 8 ++++---- pkg/system/{api/api.go => hostapi/hostapi.go} | 7 +++++-- pkg/system/{api => hostapi}/types.go | 0 pkg/system/system.go | 6 +++--- pkg/volume/{api/api.go => hostapi/hostapi.go} | 10 +++++----- pkg/volume/volume.go | 6 +++--- pkg/volume/volume_test.go | 4 ++-- 25 files changed, 61 insertions(+), 58 deletions(-) rename pkg/disk/{api/api.go => hostapi/hostapi.go} (98%) rename pkg/disk/{api => hostapi}/types.go (100%) rename pkg/filesystem/{api/api_test.go => hostapi/hostapi_test.go} (100%) rename pkg/filesystem/{api/api.go => hostapi/hotsapi.go} (95%) rename pkg/iscsi/{api/api.go => hostapi/hostapi.go} (98%) rename pkg/iscsi/{api => hostapi}/types.go (100%) rename pkg/smb/{api/api.go => hostapi/hostapi.go} (97%) rename pkg/system/{api/api.go => hostapi/hostapi.go} (95%) rename pkg/system/{api => hostapi}/types.go (100%) rename pkg/volume/{api/api.go => hostapi/hostapi.go} (98%) diff --git a/integrationtests/disk_test.go b/integrationtests/disk_test.go index 3bb20fd0..b98e663b 100644 --- a/integrationtests/disk_test.go +++ b/integrationtests/disk_test.go @@ -10,7 +10,7 @@ import ( "time" "github.com/kubernetes-csi/csi-proxy/pkg/disk" - diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/api" + diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/hostapi" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/integrationtests/filesystem_test.go b/integrationtests/filesystem_test.go index ee1fb709..bd584a05 100644 --- a/integrationtests/filesystem_test.go +++ b/integrationtests/filesystem_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/kubernetes-csi/csi-proxy/pkg/filesystem" - filesystemapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/api" + filesystemapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/hostapi" ) func TestFilesystem(t *testing.T) { diff --git a/integrationtests/iscsi_test.go b/integrationtests/iscsi_test.go index 077b66b4..480d9354 100644 --- a/integrationtests/iscsi_test.go +++ b/integrationtests/iscsi_test.go @@ -7,11 +7,11 @@ import ( "testing" disk "github.com/kubernetes-csi/csi-proxy/pkg/disk" - diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/api" + diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/hostapi" iscsi "github.com/kubernetes-csi/csi-proxy/pkg/iscsi" - iscsiapi "github.com/kubernetes-csi/csi-proxy/pkg/iscsi/api" + iscsiapi "github.com/kubernetes-csi/csi-proxy/pkg/iscsi/hostapi" system "github.com/kubernetes-csi/csi-proxy/pkg/system" - systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/api" + systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/hostapi" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/integrationtests/smb_test.go b/integrationtests/smb_test.go index b42602de..b9c67152 100644 --- a/integrationtests/smb_test.go +++ b/integrationtests/smb_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/require" fs "github.com/kubernetes-csi/csi-proxy/pkg/filesystem" - fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/api" + fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/hostapi" "github.com/kubernetes-csi/csi-proxy/pkg/smb" - smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api" + smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/hostapi" ) func TestSMB(t *testing.T) { diff --git a/integrationtests/system_test.go b/integrationtests/system_test.go index e1ca85cc..2b9dfa79 100644 --- a/integrationtests/system_test.go +++ b/integrationtests/system_test.go @@ -9,7 +9,7 @@ import ( "testing" system "github.com/kubernetes-csi/csi-proxy/pkg/system" - systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/api" + systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/hostapi" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/integrationtests/volume_test.go b/integrationtests/volume_test.go index 504d9b92..4cb1c64e 100644 --- a/integrationtests/volume_test.go +++ b/integrationtests/volume_test.go @@ -9,9 +9,9 @@ import ( "testing" disk "github.com/kubernetes-csi/csi-proxy/pkg/disk" - diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/api" + diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/hostapi" volume "github.com/kubernetes-csi/csi-proxy/pkg/volume" - volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/api" + volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/hostapi" "github.com/stretchr/testify/require" ) diff --git a/pkg/disk/disk.go b/pkg/disk/disk.go index 01dc6657..1067a8fa 100644 --- a/pkg/disk/disk.go +++ b/pkg/disk/disk.go @@ -3,12 +3,12 @@ package disk import ( "context" - diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/api" + diskapi "github.com/kubernetes-csi/csi-proxy/pkg/disk/hostapi" "k8s.io/klog/v2" ) type Disk struct { - hostAPI diskapi.API + hostAPI diskapi.HostAPI } type Interface interface { @@ -39,7 +39,7 @@ type Interface interface { // check that Disk implements Interface var _ Interface = &Disk{} -func New(hostAPI diskapi.API) (*Disk, error) { +func New(hostAPI diskapi.HostAPI) (*Disk, error) { return &Disk{ hostAPI: hostAPI, }, nil diff --git a/pkg/disk/api/api.go b/pkg/disk/hostapi/hostapi.go similarity index 98% rename from pkg/disk/api/api.go rename to pkg/disk/hostapi/hostapi.go index 15e3be16..15d0a2bb 100644 --- a/pkg/disk/api/api.go +++ b/pkg/disk/hostapi/hostapi.go @@ -23,8 +23,8 @@ const ( IOCTL_STORAGE_QUERY_PROPERTY = 0x002d1400 ) -// API declares the interface exposed by the internal API -type API interface { +// HostAPI declares the interface exposed by the internal API +type HostAPI interface { // ListDiskLocations - constructs a map with the disk number as the key and the DiskLocation structure // as the value. The DiskLocation struct has various fields like the Adapter, Bus, Target and LUNID. ListDiskLocations() (map[uint32]DiskLocation, error) @@ -55,7 +55,7 @@ type API interface { type DiskAPI struct{} // ensure that DiskAPI implements the exposed API -var _ API = &DiskAPI{} +var _ HostAPI = &DiskAPI{} func New() DiskAPI { return DiskAPI{} diff --git a/pkg/disk/api/types.go b/pkg/disk/hostapi/types.go similarity index 100% rename from pkg/disk/api/types.go rename to pkg/disk/hostapi/types.go diff --git a/pkg/filesystem/filesystem.go b/pkg/filesystem/filesystem.go index 3277ba36..f0ea43bc 100644 --- a/pkg/filesystem/filesystem.go +++ b/pkg/filesystem/filesystem.go @@ -3,12 +3,12 @@ package filesystem import ( "context" - filesystemapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/api" + filesystemapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/hostapi" "k8s.io/klog/v2" ) type Filesystem struct { - hostAPI filesystemapi.API + hostAPI filesystemapi.HostAPI } type Interface interface { @@ -41,7 +41,7 @@ type Interface interface { // check that Filesystem implements Interface var _ Interface = &Filesystem{} -func New(hostAPI filesystemapi.API) (*Filesystem, error) { +func New(hostAPI filesystemapi.HostAPI) (*Filesystem, error) { return &Filesystem{ hostAPI: hostAPI, }, nil diff --git a/pkg/filesystem/filesystem_test.go b/pkg/filesystem/filesystem_test.go index 06b6150e..d163e0cf 100644 --- a/pkg/filesystem/filesystem_test.go +++ b/pkg/filesystem/filesystem_test.go @@ -4,12 +4,12 @@ import ( "context" "testing" - fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/api" + fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/hostapi" ) type fakeFileSystemAPI struct{} -var _ fsapi.API = &fakeFileSystemAPI{} +var _ fsapi.HostAPI = &fakeFileSystemAPI{} func (fakeFileSystemAPI) PathExists(path string) (bool, error) { return true, nil diff --git a/pkg/filesystem/api/api_test.go b/pkg/filesystem/hostapi/hostapi_test.go similarity index 100% rename from pkg/filesystem/api/api_test.go rename to pkg/filesystem/hostapi/hostapi_test.go diff --git a/pkg/filesystem/api/api.go b/pkg/filesystem/hostapi/hotsapi.go similarity index 95% rename from pkg/filesystem/api/api.go rename to pkg/filesystem/hostapi/hotsapi.go index 95a492bb..12f090aa 100644 --- a/pkg/filesystem/api/api.go +++ b/pkg/filesystem/hostapi/hotsapi.go @@ -14,8 +14,8 @@ import ( // pkg/filesystem/filesystem.go so that logic can be easily unit-tested // without requiring specific OS environments. -// API is the exposed Filesystem API -type API interface { +// HostAPI is the exposed Filesystem API +type HostAPI interface { PathExists(path string) (bool, error) PathValid(path string) (bool, error) Mkdir(path string) error @@ -27,10 +27,10 @@ type API interface { type filesystemAPI struct{} -// check that filesystemAPI implements API -var _ API = &filesystemAPI{} +// check that filesystemAPI implements HostAPI +var _ HostAPI = &filesystemAPI{} -func New() API { +func New() HostAPI { return filesystemAPI{} } diff --git a/pkg/iscsi/api/api.go b/pkg/iscsi/hostapi/hostapi.go similarity index 98% rename from pkg/iscsi/api/api.go rename to pkg/iscsi/hostapi/hostapi.go index 76ea7779..d5caaa94 100644 --- a/pkg/iscsi/api/api.go +++ b/pkg/iscsi/hostapi/hostapi.go @@ -12,7 +12,7 @@ import ( // pkg/iscsi/iscsi.go so that logic can be easily unit-tested // without requiring specific OS environments. -type API interface { +type HostAPI interface { AddTargetPortal(portal *TargetPortal) error DiscoverTargetPortal(portal *TargetPortal) ([]string, error) ListTargetPortals() ([]TargetPortal, error) @@ -26,10 +26,10 @@ type API interface { type iscsiAPI struct{} -// check that iscsiAPI implements API -var _ API = &iscsiAPI{} +// check that iscsiAPI implements HostAPI +var _ HostAPI = &iscsiAPI{} -func New() API { +func New() HostAPI { return iscsiAPI{} } diff --git a/pkg/iscsi/api/types.go b/pkg/iscsi/hostapi/types.go similarity index 100% rename from pkg/iscsi/api/types.go rename to pkg/iscsi/hostapi/types.go diff --git a/pkg/iscsi/iscsi.go b/pkg/iscsi/iscsi.go index 362a2f47..7d3eddd0 100644 --- a/pkg/iscsi/iscsi.go +++ b/pkg/iscsi/iscsi.go @@ -4,14 +4,14 @@ import ( "context" "fmt" - iscsiapi "github.com/kubernetes-csi/csi-proxy/pkg/iscsi/api" + iscsiapi "github.com/kubernetes-csi/csi-proxy/pkg/iscsi/hostapi" "k8s.io/klog/v2" ) const defaultISCSIPort = 3260 type ISCSI struct { - hostAPI iscsiapi.API + hostAPI iscsiapi.HostAPI } type Interface interface { @@ -53,7 +53,7 @@ type Interface interface { var _ Interface = &ISCSI{} -func New(hostAPI iscsiapi.API) (*ISCSI, error) { +func New(hostAPI iscsiapi.HostAPI) (*ISCSI, error) { return &ISCSI{ hostAPI: hostAPI, }, nil diff --git a/pkg/smb/api/api.go b/pkg/smb/hostapi/hostapi.go similarity index 97% rename from pkg/smb/api/api.go rename to pkg/smb/hostapi/hostapi.go index fb45fefa..6ab538fc 100644 --- a/pkg/smb/api/api.go +++ b/pkg/smb/hostapi/hostapi.go @@ -7,7 +7,7 @@ import ( "github.com/kubernetes-csi/csi-proxy/pkg/utils" ) -type API interface { +type HostAPI interface { IsSMBMapped(remotePath string) (bool, error) NewSMBLink(remotePath, localPath string) error NewSMBGlobalMapping(remotePath, username, password string) error @@ -16,9 +16,9 @@ type API interface { type smbAPI struct{} -var _ API = &smbAPI{} +var _ HostAPI = &smbAPI{} -func New() API { +func New() HostAPI { return smbAPI{} } diff --git a/pkg/smb/smb.go b/pkg/smb/smb.go index 4a25e32f..e2603c2f 100644 --- a/pkg/smb/smb.go +++ b/pkg/smb/smb.go @@ -6,12 +6,12 @@ import ( "strings" fs "github.com/kubernetes-csi/csi-proxy/pkg/filesystem" - smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api" + smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/hostapi" "k8s.io/klog/v2" ) type SMB struct { - hostAPI smbapi.API + hostAPI smbapi.HostAPI fs fs.Interface } @@ -51,7 +51,7 @@ func getRootMappingPath(path string) (string, error) { return strings.ToLower("\\\\" + parts[0] + "\\" + parts[1]), nil } -func New(hostAPI smbapi.API, fsClient fs.Interface) (*SMB, error) { +func New(hostAPI smbapi.HostAPI, fsClient fs.Interface) (*SMB, error) { return &SMB{ hostAPI: hostAPI, fs: fsClient, diff --git a/pkg/smb/smb_test.go b/pkg/smb/smb_test.go index 64ad7225..3fc0cc94 100644 --- a/pkg/smb/smb_test.go +++ b/pkg/smb/smb_test.go @@ -5,13 +5,13 @@ import ( "testing" fs "github.com/kubernetes-csi/csi-proxy/pkg/filesystem" - fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/api" - smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api" + fsapi "github.com/kubernetes-csi/csi-proxy/pkg/filesystem/hostapi" + smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/hostapi" ) type fakeSMBAPI struct{} -var _ smbapi.API = &fakeSMBAPI{} +var _ smbapi.HostAPI = &fakeSMBAPI{} func (fakeSMBAPI) NewSMBGlobalMapping(remotePath, username, password string) error { return nil @@ -31,7 +31,7 @@ func (fakeSMBAPI) NewSMBLink(remotePath, localPath string) error { type fakeFileSystemAPI struct{} -var _ fsapi.API = &fakeFileSystemAPI{} +var _ fsapi.HostAPI = &fakeFileSystemAPI{} func (fakeFileSystemAPI) PathExists(path string) (bool, error) { return true, nil diff --git a/pkg/system/api/api.go b/pkg/system/hostapi/hostapi.go similarity index 95% rename from pkg/system/api/api.go rename to pkg/system/hostapi/hostapi.go index d239234e..10ed8af6 100644 --- a/pkg/system/api/api.go +++ b/pkg/system/hostapi/hostapi.go @@ -14,7 +14,7 @@ import ( // pkg/system/system.go so that logic can be easily unit-tested // without requiring specific OS environments. -type API interface { +type HostAPI interface { GetBIOSSerialNumber() (string, error) GetService(name string) (*ServiceInfo, error) StartService(name string) error @@ -23,7 +23,10 @@ type API interface { type systemAPI struct{} -func New() API { +// check that systemAPI implements HostAPI +var _ HostAPI = &systemAPI{} + +func New() HostAPI { return systemAPI{} } diff --git a/pkg/system/api/types.go b/pkg/system/hostapi/types.go similarity index 100% rename from pkg/system/api/types.go rename to pkg/system/hostapi/types.go diff --git a/pkg/system/system.go b/pkg/system/system.go index 88bfc817..e4fd1541 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -3,12 +3,12 @@ package system import ( "context" - systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/api" + systemapi "github.com/kubernetes-csi/csi-proxy/pkg/system/hostapi" "k8s.io/klog/v2" ) type System struct { - hostAPI systemapi.API + hostAPI systemapi.HostAPI } type Interface interface { @@ -32,7 +32,7 @@ type Interface interface { // check that System implements Interface var _ Interface = &System{} -func New(hostAPI systemapi.API) (*System, error) { +func New(hostAPI systemapi.HostAPI) (*System, error) { return &System{ hostAPI: hostAPI, }, nil diff --git a/pkg/volume/api/api.go b/pkg/volume/hostapi/hostapi.go similarity index 98% rename from pkg/volume/api/api.go rename to pkg/volume/hostapi/hostapi.go index 440ecfae..2ed36b1b 100644 --- a/pkg/volume/api/api.go +++ b/pkg/volume/hostapi/hostapi.go @@ -13,8 +13,8 @@ import ( "k8s.io/klog/v2" ) -// API exposes the internal volume operations available in the server -type API interface { +// HostAPI exposes the internal volume operations available in the server +type HostAPI interface { // ListVolumesOnDisk lists volumes on a disk identified by a `diskNumber` and optionally a partition identified by `partitionNumber`. ListVolumesOnDisk(diskNumber uint32, partitionNumber uint32) (volumeIDs []string, err error) // MountVolume mounts the volume at the requested global staging target path. @@ -42,8 +42,8 @@ type API interface { // volumeAPI implements the internal Volume APIs type volumeAPI struct{} -// verifies that the API is implemented -var _ API = &volumeAPI{} +// verifies that HostAPI is implemented +var _ HostAPI = &volumeAPI{} var ( // VolumeRegexp matches a Windows Volume @@ -57,7 +57,7 @@ var ( ) // New - Construct a new Volume API Implementation. -func New() API { +func New() HostAPI { return &volumeAPI{} } diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index 26fdf251..aafbe56a 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -4,13 +4,13 @@ import ( "context" "fmt" - volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/api" + volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/hostapi" "k8s.io/klog/v2" ) // Volume wraps the host API and implements the interface type Volume struct { - hostAPI volumeapi.API + hostAPI volumeapi.HostAPI } type Interface interface { @@ -53,7 +53,7 @@ type Interface interface { var _ Interface = &Volume{} -func New(hostAPI volumeapi.API) (*Volume, error) { +func New(hostAPI volumeapi.HostAPI) (*Volume, error) { return &Volume{ hostAPI: hostAPI, }, nil diff --git a/pkg/volume/volume_test.go b/pkg/volume/volume_test.go index 3c4ddf5e..f57957f4 100644 --- a/pkg/volume/volume_test.go +++ b/pkg/volume/volume_test.go @@ -5,14 +5,14 @@ import ( "fmt" "testing" - volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/api" + volumeapi "github.com/kubernetes-csi/csi-proxy/pkg/volume/hostapi" ) type fakeVolumeAPI struct { diskVolMap map[uint32][]string } -var _ volumeapi.API = &fakeVolumeAPI{} +var _ volumeapi.HostAPI = &fakeVolumeAPI{} func (volumeAPI *fakeVolumeAPI) Fill(diskToVolMapIn map[uint32][]string) { for d, v := range diskToVolMapIn {