Skip to content

Commit

Permalink
expose driver capabilities to csi_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed May 20, 2020
1 parent 169d88f commit 5c5a0c4
Show file tree
Hide file tree
Showing 4 changed files with 33 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
19 changes: 18 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,21 @@ 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)
}
switch caps.Volumes {
case drivers.VolumeSupportNone, drivers.VolumeSupportHostOnly:
return nil, fmt.Errorf("task driver does not support CSI")
default:
}
}

result[alias] = &volumeAndRequest{request: volumeRequest}
}
}
Expand Down Expand Up @@ -125,8 +141,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
2 changes: 2 additions & 0 deletions plugins/drivers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (d *driverPluginClient) Capabilities() (*Capabilities, error) {
default:
caps.FSIsolation = FSIsolationNone
}

caps.Volumes = VolumeSupport(resp.Capabilities.Volumes)
}

return caps, nil
Expand Down
12 changes: 12 additions & 0 deletions plugins/drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ type Capabilities struct {
// MustInitiateNetwork tells Nomad that the driver must create the network
// namespace and that the CreateNetwork and DestroyNetwork RPCs are implemented.
MustInitiateNetwork bool

// Volumes tells Nomad which volume mounting options the driver supports.
Volumes VolumeSupport
}

func (c *Capabilities) HasNetIsolationMode(m NetIsolationMode) bool {
Expand Down Expand Up @@ -197,6 +200,15 @@ type NetworkIsolationSpec struct {
Labels map[string]string
}

type VolumeSupport int32

const (
VolumeSupportAll VolumeSupport = iota
VolumeSupportNone
VolumeSupportHostOnly
VolumeSupportCSIOnly
)

type TerminalSize struct {
Height int
Width int
Expand Down

0 comments on commit 5c5a0c4

Please sign in to comment.