Skip to content

Commit

Permalink
csi: refactor to use opts struct for plugin supervisor hook config
Browse files Browse the repository at this point in the history
The parameter list for configuring the plugin supervisor hook has
grown enough where is makes sense to use an options struct similiar to
many of the other task runner hooks (ex. template).
  • Loading branch information
tgross committed Feb 10, 2022
1 parent 89a75af commit f9f6c64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
25 changes: 17 additions & 8 deletions client/allocrunner/taskrunner/plugin_supervisor_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ type csiPluginSupervisorHook struct {
previousHealthState bool
}

type csiPluginSupervisorHookConfig struct {
clientStateDirPath string
events ti.EventEmitter
runner *TaskRunner
capabilities *drivers.Capabilities
logger hclog.Logger
}

// The plugin supervisor uses the PrestartHook mechanism to setup the requisite
// mount points and configuration for the task that exposes a CSI plugin.
var _ interfaces.TaskPrestartHook = &csiPluginSupervisorHook{}
Expand All @@ -63,8 +71,8 @@ var _ interfaces.TaskPoststartHook = &csiPluginSupervisorHook{}
// with the catalog and to ensure any mounts are cleaned up.
var _ interfaces.TaskStopHook = &csiPluginSupervisorHook{}

func newCSIPluginSupervisorHook(csiRootDir string, eventEmitter ti.EventEmitter, runner *TaskRunner, caps *drivers.Capabilities, logger hclog.Logger) *csiPluginSupervisorHook {
task := runner.Task()
func newCSIPluginSupervisorHook(config *csiPluginSupervisorHookConfig) *csiPluginSupervisorHook {
task := config.runner.Task()

// The Plugin directory will look something like this:
// .
Expand All @@ -74,20 +82,21 @@ func newCSIPluginSupervisorHook(csiRootDir string, eventEmitter ti.EventEmitter,
// {volume-id}/{usage-mode-hash}/ - Intermediary mount point that will be used by plugins that support NODE_STAGE_UNSTAGE capabilities.
// per-alloc/
// {alloc-id}/{volume-id}/{usage-mode-hash}/ - Mount Point that will be bind-mounted into tasks that utilise the volume
pluginRoot := filepath.Join(csiRootDir, string(task.CSIPluginConfig.Type), task.CSIPluginConfig.ID)
pluginRoot := filepath.Join(config.clientStateDirPath, "csi",
string(task.CSIPluginConfig.Type), task.CSIPluginConfig.ID)

shutdownCtx, cancelFn := context.WithCancel(context.Background())

hook := &csiPluginSupervisorHook{
alloc: runner.Alloc(),
runner: runner,
logger: logger,
alloc: config.runner.Alloc(),
runner: config.runner,
logger: config.logger,
task: task,
mountPoint: pluginRoot,
caps: caps,
caps: config.capabilities,
shutdownCtx: shutdownCtx,
shutdownCancelFn: cancelFn,
eventEmitter: eventEmitter,
eventEmitter: config.events,
}

return hook
Expand Down
10 changes: 8 additions & 2 deletions client/allocrunner/taskrunner/task_runner_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package taskrunner
import (
"context"
"fmt"
"path/filepath"
"sync"
"time"

Expand Down Expand Up @@ -72,7 +71,14 @@ func (tr *TaskRunner) initHooks() {

// If the task has a CSI stanza, add the hook.
if task.CSIPluginConfig != nil {
tr.runnerHooks = append(tr.runnerHooks, newCSIPluginSupervisorHook(filepath.Join(tr.clientConfig.StateDir, "csi"), tr, tr, tr.driverCapabilities, hookLogger))
tr.runnerHooks = append(tr.runnerHooks, newCSIPluginSupervisorHook(
&csiPluginSupervisorHookConfig{
clientStateDirPath: tr.clientConfig.StateDir,
events: tr,
runner: tr,
capabilities: tr.driverCapabilities,
logger: hookLogger,
}))
}

// If Vault is enabled, add the hook
Expand Down

0 comments on commit f9f6c64

Please sign in to comment.