2020-01-08 12:47:07 +00:00
|
|
|
package allocrunner
|
|
|
|
|
|
|
|
import (
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2020-02-11 13:30:34 +00:00
|
|
|
alloc *structs.Allocation
|
|
|
|
logger hclog.Logger
|
|
|
|
rpcClient RPCer
|
2020-01-08 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *csiHook) Name() string {
|
|
|
|
return "csi_hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *csiHook) Prerun() error {
|
|
|
|
if !c.shouldRun() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Volume attachment flow
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-11 13:30:34 +00:00
|
|
|
func newCSIHook(logger hclog.Logger, alloc *structs.Allocation, rpcClient RPCer) *csiHook {
|
2020-01-08 12:47:07 +00:00
|
|
|
return &csiHook{
|
2020-02-11 13:30:34 +00:00
|
|
|
alloc: alloc,
|
|
|
|
logger: logger.Named("csi_hook"),
|
|
|
|
rpcClient: rpcClient,
|
2020-01-08 12:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *csiHook) shouldRun() bool {
|
|
|
|
tg := h.alloc.Job.LookupTaskGroup(h.alloc.TaskGroup)
|
|
|
|
for _, vol := range tg.Volumes {
|
|
|
|
if vol.Type == structs.VolumeTypeCSI {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|