mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 03:45:41 +03:00
While working on #25373, I noticed that the CSI hook's `Destroy` method doesn't match the interface, which means it never gets called. Because this method only cancels any in-flight CSI requests, the only impact of this bug is that any CSI RPCs that are in-flight when an alloc is GC'd on the client or a dev agent is shut down won't be interrupted gracefully. Fix the interface, but also make static assertions for all the allocrunner hooks in the production code, so that you can make changes to interfaces and have compile-time assistance in avoiding mistakes. Ref: https://github.com/hashicorp/nomad/pull/25373
44 lines
999 B
Go
44 lines
999 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package allocrunner
|
|
|
|
import (
|
|
"github.com/hashicorp/go-hclog"
|
|
"github.com/hashicorp/nomad/client/allocdir"
|
|
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
|
|
)
|
|
|
|
// allocDirHook creates and destroys the root directory and shared directories
|
|
// for an allocation.
|
|
type allocDirHook struct {
|
|
allocDir allocdir.Interface
|
|
logger hclog.Logger
|
|
}
|
|
|
|
func newAllocDirHook(logger hclog.Logger, allocDir allocdir.Interface) *allocDirHook {
|
|
ad := &allocDirHook{
|
|
allocDir: allocDir,
|
|
}
|
|
ad.logger = logger.Named(ad.Name())
|
|
return ad
|
|
}
|
|
|
|
// statically assert that the hook meets the expected interfaces
|
|
var (
|
|
_ interfaces.RunnerPrerunHook = (*allocDirHook)(nil)
|
|
_ interfaces.RunnerDestroyHook = (*allocDirHook)(nil)
|
|
)
|
|
|
|
func (h *allocDirHook) Name() string {
|
|
return "alloc_dir"
|
|
}
|
|
|
|
func (h *allocDirHook) Prerun() error {
|
|
return h.allocDir.Build()
|
|
}
|
|
|
|
func (h *allocDirHook) Destroy() error {
|
|
return h.allocDir.Destroy()
|
|
}
|