2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-10-04 23:22:01 +00:00
|
|
|
package allocrunner
|
2018-08-31 00:13:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/nomad/client/allocdir"
|
|
|
|
)
|
|
|
|
|
|
|
|
// allocDirHook creates and destroys the root directory and shared directories
|
|
|
|
// for an allocation.
|
|
|
|
type allocDirHook struct {
|
|
|
|
allocDir *allocdir.AllocDir
|
|
|
|
logger log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAllocDirHook(logger log.Logger, allocDir *allocdir.AllocDir) *allocDirHook {
|
|
|
|
ad := &allocDirHook{
|
|
|
|
allocDir: allocDir,
|
|
|
|
}
|
|
|
|
ad.logger = logger.Named(ad.Name())
|
|
|
|
return ad
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *allocDirHook) Name() string {
|
|
|
|
return "alloc_dir"
|
|
|
|
}
|
|
|
|
|
2019-03-12 22:03:54 +00:00
|
|
|
func (h *allocDirHook) Prerun() error {
|
2018-08-31 00:13:00 +00:00
|
|
|
return h.allocDir.Build()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *allocDirHook) Destroy() error {
|
|
|
|
return h.allocDir.Destroy()
|
|
|
|
}
|