mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
When we introduced change_mode=script to templates, we passed the driver handle down into the template manager so we could call its `Exec` method directly. But the lifecycle of the driver handle is managed by the taskrunner and isn't available when the template manager is first created. This has led to a series of patches trying to fixup the behavior (#15915, #15192, #23663, #23917). Part of the challenge in getting this right is using an interface to avoid the circular import of the driver handle. But the taskrunner already has a way to deal with this problem using a "lazy handle". The other template change modes already use this indirectly through the `Lifecycle` interface. Change the driver handle `Exec` call in the template manager to a new `Lifecycle.Exec` call that reuses the existing behavior. This eliminates the need for the template manager to know anything at all about the handle state. Fixes: https://github.com/hashicorp/nomad/issues/24051
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package interfaces
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
type TaskLifecycle interface {
|
|
// Restart a task in place. If failure=false then the restart does not
|
|
// count as an attempt in the restart policy.
|
|
Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
|
|
|
|
// Sends a signal to a task.
|
|
Signal(event *structs.TaskEvent, signal string) error
|
|
|
|
// Kill a task permanently.
|
|
Kill(ctx context.Context, event *structs.TaskEvent) error
|
|
|
|
// Exec into a running task.
|
|
Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)
|
|
|
|
// IsRunning returns true if the task runner has a handle to the task
|
|
// driver, which is useful for distinguishing restored tasks during
|
|
// prestart hooks. But note that the driver handle could go away after you
|
|
// check this, so callers should make sure they're handling that case
|
|
// safely. Ideally prestart hooks should be idempotent whenever possible
|
|
// to handle restored tasks; use this as an escape hatch.
|
|
IsRunning() bool
|
|
}
|