Skip to content

Commit

Permalink
add MountConfig capability checking to csi_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed May 20, 2020
1 parent 7ac93f5 commit 3f3e570
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/allocrunner/alloc_runner_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (ar *allocRunner) initRunnerHooks(config *clientconfig.Config) error {
logger: hookLogger,
}),
newConsulSockHook(hookLogger, alloc, ar.allocDir, config.ConsulConfig),
newCSIHook(hookLogger, alloc, ar.rpcClient, ar.csiManager, hrs),
newCSIHook(ar, hookLogger, alloc, ar.rpcClient, ar.csiManager, hrs),
}

return nil
Expand Down
18 changes: 17 additions & 1 deletion client/allocrunner/csi_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/drivers"
)

// csiHook will wait for remote csi volumes to be attached to the host before
// continuing.
//
// It is a noop for allocs that do not depend on CSI Volumes.
type csiHook struct {
ar *allocRunner
alloc *structs.Allocation
logger hclog.Logger
csimanager csimanager.Manager
Expand Down Expand Up @@ -88,7 +90,20 @@ func (c *csiHook) claimVolumesFromAlloc() (map[string]*volumeAndRequest, error)

// Initially, populate the result map with all of the requests
for alias, volumeRequest := range tg.Volumes {

if volumeRequest.Type == structs.VolumeTypeCSI {

for _, task := range tg.Tasks {
caps, err := c.ar.GetTaskDriverCapabilities(task.Name)
if err != nil {
return nil, fmt.Errorf("could not validate task driver capabilities: %v", err)
}

if caps.MountConfigs == drivers.MountConfigSupportNone {
return nil, fmt.Errorf("task driver does not support CSI")
}
}

result[alias] = &volumeAndRequest{request: volumeRequest}
}
}
Expand Down Expand Up @@ -125,8 +140,9 @@ func (c *csiHook) claimVolumesFromAlloc() (map[string]*volumeAndRequest, error)
return result, nil
}

func newCSIHook(logger hclog.Logger, alloc *structs.Allocation, rpcClient RPCer, csi csimanager.Manager, updater hookResourceSetter) *csiHook {
func newCSIHook(ar *allocRunner, logger hclog.Logger, alloc *structs.Allocation, rpcClient RPCer, csi csimanager.Manager, updater hookResourceSetter) *csiHook {
return &csiHook{
ar: ar,
alloc: alloc,
logger: logger.Named("csi_hook"),
rpcClient: rpcClient,
Expand Down

0 comments on commit 3f3e570

Please sign in to comment.