Skip to content

Commit

Permalink
backport of commit 22cbb91 (#18435)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Bennett <dbennett@hashicorp.com>
  • Loading branch information
hc-github-team-nomad-core and gulducat committed Sep 8, 2023
1 parent efed338 commit 0883a44
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions client/allocrunner/csi_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ func (c *csiHook) restoreMounts(results map[string]*volumePublishResult) error {
}
c.logger.Debug("found CSI plugin", "type", pType, "name", plugin)

mounter, err := c.csimanager.MounterForPlugin(c.shutdownCtx, plugin)
manager, err := c.csimanager.ManagerForPlugin(c.shutdownCtx, plugin)
if err != nil {
return err
}

isMounted, err := mounter.HasMount(c.shutdownCtx, result.stub.MountInfo)
isMounted, err := manager.HasMount(c.shutdownCtx, result.stub.MountInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func (c *csiHook) mountVolumes(results map[string]*volumePublishResult) error {
}
c.logger.Debug("found CSI plugin", "type", pType, "name", plugin)

mounter, err := c.csimanager.MounterForPlugin(c.shutdownCtx, plugin)
manager, err := c.csimanager.ManagerForPlugin(c.shutdownCtx, plugin)
if err != nil {
return err
}
Expand All @@ -359,7 +359,7 @@ func (c *csiHook) mountVolumes(results map[string]*volumePublishResult) error {
MountOptions: result.request.MountOptions,
}

mountInfo, err := mounter.MountVolume(
mountInfo, err := manager.MountVolume(
c.shutdownCtx, result.volume, c.alloc, usageOpts, result.publishContext)
if err != nil {
return err
Expand Down Expand Up @@ -516,7 +516,7 @@ func (c *csiHook) unmountWithRetry(result *volumePublishResult) error {
// NodeEvent
func (c *csiHook) unmountImpl(result *volumePublishResult) error {

mounter, err := c.csimanager.MounterForPlugin(c.shutdownCtx, result.stub.PluginID)
manager, err := c.csimanager.ManagerForPlugin(c.shutdownCtx, result.stub.PluginID)
if err != nil {
return err
}
Expand All @@ -528,7 +528,7 @@ func (c *csiHook) unmountImpl(result *volumePublishResult) error {
MountOptions: result.request.MountOptions,
}

return mounter.UnmountVolume(c.shutdownCtx,
return manager.UnmountVolume(c.shutdownCtx,
result.stub.VolumeID, result.stub.VolumeExternalID, c.alloc.ID, usageOpts)
}

Expand Down
18 changes: 9 additions & 9 deletions client/allocrunner/csi_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestCSIHook(t *testing.T) {
alloc.Job.TaskGroups[0].Volumes = tc.volumeRequests

callCounts := &callCounter{counts: map[string]int{}}
mgr := mockPluginManager{mounter: mockVolumeMounter{
mgr := mockPluginManager{mounter: mockVolumeManager{
hasMounts: tc.startsWithValidMounts,
callCounts: callCounts,
failsFirstUnmount: pointer.Of(tc.failsFirstUnmount),
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestCSIHook_Prerun_Validation(t *testing.T) {
alloc.Job.TaskGroups[0].Volumes = volumeRequests

callCounts := &callCounter{counts: map[string]int{}}
mgr := mockPluginManager{mounter: mockVolumeMounter{
mgr := mockPluginManager{mounter: mockVolumeManager{
callCounts: callCounts,
failsFirstUnmount: pointer.Of(false),
}}
Expand Down Expand Up @@ -466,20 +466,20 @@ func (r mockRPCer) testVolume(id string) *structs.CSIVolume {
return vol
}

type mockVolumeMounter struct {
type mockVolumeManager struct {
hasMounts bool
failsFirstUnmount *bool
callCounts *callCounter
}

func (vm mockVolumeMounter) MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *csimanager.UsageOptions, publishContext map[string]string) (*csimanager.MountInfo, error) {
func (vm mockVolumeManager) MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *csimanager.UsageOptions, publishContext map[string]string) (*csimanager.MountInfo, error) {
vm.callCounts.inc("mount")
return &csimanager.MountInfo{
Source: filepath.Join("test-alloc-dir", alloc.ID, vol.ID, usageOpts.ToFS()),
}, nil
}

func (vm mockVolumeMounter) UnmountVolume(ctx context.Context, volID, remoteID, allocID string, usageOpts *csimanager.UsageOptions) error {
func (vm mockVolumeManager) UnmountVolume(ctx context.Context, volID, remoteID, allocID string, usageOpts *csimanager.UsageOptions) error {
vm.callCounts.inc("unmount")

if *vm.failsFirstUnmount {
Expand All @@ -490,24 +490,24 @@ func (vm mockVolumeMounter) UnmountVolume(ctx context.Context, volID, remoteID,
return nil
}

func (vm mockVolumeMounter) HasMount(_ context.Context, mountInfo *csimanager.MountInfo) (bool, error) {
func (vm mockVolumeManager) HasMount(_ context.Context, mountInfo *csimanager.MountInfo) (bool, error) {
vm.callCounts.inc("hasMount")
return mountInfo != nil && vm.hasMounts, nil
}

func (vm mockVolumeMounter) ExternalID() string {
func (vm mockVolumeManager) ExternalID() string {
return "i-example"
}

type mockPluginManager struct {
mounter mockVolumeMounter
mounter mockVolumeManager
}

func (mgr mockPluginManager) WaitForPlugin(ctx context.Context, pluginType, pluginID string) error {
return nil
}

func (mgr mockPluginManager) MounterForPlugin(ctx context.Context, pluginID string) (csimanager.VolumeMounter, error) {
func (mgr mockPluginManager) ManagerForPlugin(ctx context.Context, pluginID string) (csimanager.VolumeManager, error) {
return mgr.mounter, nil
}

Expand Down
4 changes: 2 additions & 2 deletions client/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (c *CSI) NodeDetachVolume(req *structs.ClientCSINodeDetachVolumeRequest, re
ctx, cancelFn := c.requestContext()
defer cancelFn()

mounter, err := c.c.csimanager.MounterForPlugin(ctx, req.PluginID)
manager, err := c.c.csimanager.ManagerForPlugin(ctx, req.PluginID)
if err != nil {
return fmt.Errorf("CSI.NodeDetachVolume: %v", err)
}
Expand All @@ -482,7 +482,7 @@ func (c *CSI) NodeDetachVolume(req *structs.ClientCSINodeDetachVolumeRequest, re
AccessMode: req.AccessMode,
}

err = mounter.UnmountVolume(ctx, req.VolumeID, req.ExternalID, req.AllocID, usageOpts)
err = manager.UnmountVolume(ctx, req.VolumeID, req.ExternalID, req.AllocID, usageOpts)
if err != nil && !errors.Is(err, nstructs.ErrCSIClientRPCIgnorable) {
// if the unmounting previously happened but the server failed to
// checkpoint, we'll get an error from Unmount but can safely
Expand Down
4 changes: 2 additions & 2 deletions client/pluginmanager/csimanager/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func (i *instanceManager) setupVolumeManager() {
}
}

// VolumeMounter returns the volume manager that is configured for the given plugin
// VolumeManager returns the volume manager that is configured for the given plugin
// instance. If called before the volume manager has been setup, it will block until
// the volume manager is ready or the context is closed.
func (i *instanceManager) VolumeMounter(ctx context.Context) (VolumeMounter, error) {
func (i *instanceManager) VolumeManager(ctx context.Context) (VolumeManager, error) {
select {
case <-i.volumeManagerSetupCh:
return i.volumeManager, nil
Expand Down
6 changes: 3 additions & 3 deletions client/pluginmanager/csimanager/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (u *UsageOptions) ToFS() string {
return sb.String()
}

type VolumeMounter interface {
type VolumeManager interface {
MountVolume(ctx context.Context, vol *structs.CSIVolume, alloc *structs.Allocation, usageOpts *UsageOptions, publishContext map[string]string) (*MountInfo, error)
UnmountVolume(ctx context.Context, volID, remoteID, allocID string, usageOpts *UsageOptions) error
HasMount(ctx context.Context, mountInfo *MountInfo) (bool, error)
Expand All @@ -65,9 +65,9 @@ type Manager interface {
// or until its context is canceled or times out.
WaitForPlugin(ctx context.Context, pluginType, pluginID string) error

// MounterForPlugin returns a VolumeMounter for the plugin ID associated
// ManagerForPlugin returns a VolumeManager for the plugin ID associated
// with the volume. Returns an error if this plugin isn't registered.
MounterForPlugin(ctx context.Context, pluginID string) (VolumeMounter, error)
ManagerForPlugin(ctx context.Context, pluginID string) (VolumeManager, error)

// Shutdown shuts down the Manager and unmounts any locally attached volumes.
Shutdown()
Expand Down
4 changes: 2 additions & 2 deletions client/pluginmanager/csimanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *csiManager) WaitForPlugin(ctx context.Context, pType, pID string) error
return nil
}

func (c *csiManager) MounterForPlugin(ctx context.Context, pluginID string) (VolumeMounter, error) {
func (c *csiManager) ManagerForPlugin(ctx context.Context, pluginID string) (VolumeManager, error) {
c.instancesLock.RLock()
defer c.instancesLock.RUnlock()
nodePlugins, hasAnyNodePlugins := c.instances["csi-node"]
Expand All @@ -103,7 +103,7 @@ func (c *csiManager) MounterForPlugin(ctx context.Context, pluginID string) (Vol
return nil, fmt.Errorf("plugin %s for type csi-node not found", pluginID)
}

return mgr.VolumeMounter(ctx)
return mgr.VolumeManager(ctx)
}

// Run starts a plugin manager and should return early
Expand Down
2 changes: 1 addition & 1 deletion client/pluginmanager/csimanager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/nomad/plugins/csi"
)

var _ VolumeMounter = &volumeManager{}
var _ VolumeManager = &volumeManager{}

const (
DefaultMountActionTimeout = 2 * time.Minute
Expand Down

0 comments on commit 0883a44

Please sign in to comment.