Skip to content

Commit

Permalink
Allow specification of CSI staging and publishing directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
ejweber committed Jul 25, 2022
1 parent 1d3ee6a commit ca3c585
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 13 additions & 6 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,17 @@ type TaskCSIPluginConfig struct {
// CSIPluginType instructs Nomad on how to handle processing a plugin
Type CSIPluginType `mapstructure:"type" hcl:"type,optional"`

// MountDir is the destination that nomad should mount in its CSI
// directory for the plugin. It will then expect a file called CSISocketName
// to be created by the plugin, and will provide references into
// "MountDir/CSIIntermediaryDirname/VolumeName/AllocID for mounts.
//
// Default is /csi.
// MountDir is the directory (within its container) in which the plugin creates a
// socket (called CSISocketName) for communication with Nomad. Default is /csi.
MountDir string `mapstructure:"mount_dir" hcl:"mount_dir,optional"`

// StagePublishDir is the base directory (within its container) in which the plugin
// mounts volumes being staged and bind mounts volumes being published.
// e.g. staging_target_path = {StagePublishDir}/staging/{volume-id}/{usage-mode}
// e.g. target_path = {StagePublishDir}/per-alloc/{alloc-id}/{volume-id}/{usage-mode}
// Default is /local/csi.
StagePublishDir string `mapstructure:"stage_publish_dir" hcl:"stage_publish_dir,optional"`

// HealthTimeout is the time after which the CSI plugin tasks will be killed
// if the CSI Plugin is not healthy.
HealthTimeout time.Duration `mapstructure:"health_timeout" hcl:"health_timeout,optional"`
Expand All @@ -1050,6 +1053,10 @@ func (t *TaskCSIPluginConfig) Canonicalize() {
t.MountDir = "/csi"
}

if t.StagePublishDir == "" {
t.StagePublishDir = filepath.Join("/local", "csi")
}

if t.HealthTimeout == 0 {
t.HealthTimeout = 30 * time.Second
}
Expand Down
6 changes: 3 additions & 3 deletions client/allocrunner/taskrunner/plugin_supervisor_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ func (h *csiPluginSupervisorHook) Prestart(ctx context.Context,
}
// where the staging and per-alloc directories will be mounted
volumeStagingMounts := &drivers.MountConfig{
// TODO(tgross): add this TaskPath to the CSIPluginConfig as well
TaskPath: "/local/csi",
TaskPath: h.task.CSIPluginConfig.StagePublishDir,
HostPath: h.mountPoint,
Readonly: false,
PropagationMode: "bidirectional",
}
h.logger.Info("", "volumeStagingMounts", volumeStagingMounts) // TODO: Remove this before merge.
// devices from the host
devMount := &drivers.MountConfig{
TaskPath: "/dev",
Expand Down Expand Up @@ -360,7 +360,7 @@ func (h *csiPluginSupervisorHook) registerPlugin(client csi.CSIPlugin, socketPat
Options: map[string]string{
"Provider": info.Name, // vendor name
"MountPoint": h.mountPoint,
"ContainerMountPoint": "/local/csi",
"ContainerMountPoint": h.task.CSIPluginConfig.StagePublishDir,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ func ApiCSIPluginConfigToStructsCSIPluginConfig(apiConfig *api.TaskCSIPluginConf
sc.ID = apiConfig.ID
sc.Type = structs.CSIPluginType(apiConfig.Type)
sc.MountDir = apiConfig.MountDir
sc.StagePublishDir = apiConfig.StagePublishDir
sc.HealthTimeout = apiConfig.HealthTimeout
return sc
}
Expand Down
13 changes: 9 additions & 4 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ type TaskCSIPluginConfig struct {
// Type instructs Nomad on how to handle processing a plugin
Type CSIPluginType

// MountDir is the destination that nomad should mount in its CSI
// directory for the plugin. It will then expect a file called CSISocketName
// to be created by the plugin, and will provide references into
// "MountDir/CSIIntermediaryDirname/{VolumeName}/{AllocID} for mounts.
// MountDir is the directory (within its container) in which the plugin creates a
// socket (called CSISocketName) for communication with Nomad. Default is /csi.
MountDir string

// StagePublishDir is the base directory (within its container) in which the plugin
// mounts volumes being staged and bind mount volumes being published.
// e.g. staging_target_path = {StagePublishDir}/staging/{volume-id}/{usage-mode}
// e.g. target_path = {StagePublishDir}/per-alloc/{alloc-id}/{volume-id}/{usage-mode}
// Default is /local/csi.
StagePublishDir string

// HealthTimeout is the time after which the CSI plugin tasks will be killed
// if the CSI Plugin is not healthy.
HealthTimeout time.Duration `mapstructure:"health_timeout" hcl:"health_timeout,optional"`
Expand Down

0 comments on commit ca3c585

Please sign in to comment.