2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-12-05 18:18:04 +00:00
|
|
|
package allocrunner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
2023-05-12 17:29:44 +00:00
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2018-12-05 18:18:04 +00:00
|
|
|
)
|
|
|
|
|
2018-12-06 11:15:59 +00:00
|
|
|
// upstreamAllocsHook waits for a PrevAllocWatcher to exit before allowing
|
2018-12-05 18:18:04 +00:00
|
|
|
// an allocation to be executed
|
2018-12-06 11:15:59 +00:00
|
|
|
type upstreamAllocsHook struct {
|
2023-05-12 17:29:44 +00:00
|
|
|
allocWatcher config.PrevAllocWatcher
|
2018-12-05 18:18:04 +00:00
|
|
|
logger log.Logger
|
|
|
|
}
|
|
|
|
|
2023-05-12 17:29:44 +00:00
|
|
|
func newUpstreamAllocsHook(logger log.Logger, allocWatcher config.PrevAllocWatcher) *upstreamAllocsHook {
|
2018-12-06 11:15:59 +00:00
|
|
|
h := &upstreamAllocsHook{
|
2018-12-05 18:18:04 +00:00
|
|
|
allocWatcher: allocWatcher,
|
|
|
|
}
|
|
|
|
h.logger = logger.Named(h.Name())
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:15:59 +00:00
|
|
|
func (h *upstreamAllocsHook) Name() string {
|
|
|
|
return "await_previous_allocations"
|
2018-12-05 18:18:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 22:03:54 +00:00
|
|
|
func (h *upstreamAllocsHook) Prerun() error {
|
2018-12-05 18:18:04 +00:00
|
|
|
// Wait for a previous alloc - if any - to terminate
|
2019-03-12 22:03:54 +00:00
|
|
|
return h.allocWatcher.Wait(context.Background())
|
2018-12-05 18:18:04 +00:00
|
|
|
}
|