address comments
This commit is contained in:
parent
80f6ce50c0
commit
c9765deff1
|
@ -12,7 +12,9 @@ import (
|
||||||
"github.com/hashicorp/nomad/client/allocrunnerv2/interfaces"
|
"github.com/hashicorp/nomad/client/allocrunnerv2/interfaces"
|
||||||
"github.com/hashicorp/nomad/client/allocrunnerv2/state"
|
"github.com/hashicorp/nomad/client/allocrunnerv2/state"
|
||||||
"github.com/hashicorp/nomad/client/allocrunnerv2/taskrunner"
|
"github.com/hashicorp/nomad/client/allocrunnerv2/taskrunner"
|
||||||
|
"github.com/hashicorp/nomad/client/config"
|
||||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||||
|
"github.com/hashicorp/nomad/client/vaultclient"
|
||||||
"github.com/hashicorp/nomad/nomad/structs"
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +23,10 @@ type allocRunner struct {
|
||||||
// Logger is the logger for the alloc runner.
|
// Logger is the logger for the alloc runner.
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
config *Config
|
clientConfig *config.Config
|
||||||
|
|
||||||
|
// vaultClient is the used to manage Vault tokens
|
||||||
|
vaultClient vaultclient.VaultClient
|
||||||
|
|
||||||
// waitCh is closed when the alloc runner has transitioned to a terminal
|
// waitCh is closed when the alloc runner has transitioned to a terminal
|
||||||
// state
|
// state
|
||||||
|
@ -54,12 +59,13 @@ type allocRunner struct {
|
||||||
// NewAllocRunner returns a new allocation runner.
|
// NewAllocRunner returns a new allocation runner.
|
||||||
func NewAllocRunner(config *Config) *allocRunner {
|
func NewAllocRunner(config *Config) *allocRunner {
|
||||||
ar := &allocRunner{
|
ar := &allocRunner{
|
||||||
config: config,
|
clientConfig: config.ClientConfig,
|
||||||
alloc: config.Alloc,
|
vaultClient: config.Vault,
|
||||||
tasks: make(map[string]*taskrunner.TaskRunner),
|
alloc: config.Alloc,
|
||||||
waitCh: make(chan struct{}),
|
tasks: make(map[string]*taskrunner.TaskRunner),
|
||||||
updateCh: make(chan *structs.Allocation),
|
waitCh: make(chan struct{}),
|
||||||
stateDB: config.StateDB,
|
updateCh: make(chan *structs.Allocation),
|
||||||
|
stateDB: config.StateDB,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create alloc dir
|
// Create alloc dir
|
||||||
|
@ -158,12 +164,12 @@ func (ar *allocRunner) runTask(alloc *structs.Allocation, task *structs.Task) er
|
||||||
// Create the runner
|
// Create the runner
|
||||||
config := &taskrunner.Config{
|
config := &taskrunner.Config{
|
||||||
Alloc: alloc,
|
Alloc: alloc,
|
||||||
ClientConfig: ar.config.ClientConfig,
|
ClientConfig: ar.clientConfig,
|
||||||
Task: task,
|
Task: task,
|
||||||
TaskDir: ar.allocDir.NewTaskDir(task.Name),
|
TaskDir: ar.allocDir.NewTaskDir(task.Name),
|
||||||
Logger: ar.logger,
|
Logger: ar.logger,
|
||||||
StateDB: ar.stateDB,
|
StateDB: ar.stateDB,
|
||||||
VaultClient: ar.config.Vault,
|
VaultClient: ar.vaultClient,
|
||||||
}
|
}
|
||||||
tr, err := taskrunner.NewTaskRunner(config)
|
tr, err := taskrunner.NewTaskRunner(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -184,11 +184,9 @@ func (h *vaultHook) run(token string) {
|
||||||
OUTER:
|
OUTER:
|
||||||
for {
|
for {
|
||||||
// Check if we should exit
|
// Check if we should exit
|
||||||
select {
|
if h.ctx.Err() != nil {
|
||||||
case <-h.ctx.Done():
|
|
||||||
stopRenewal()
|
stopRenewal()
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the token
|
// Clear the token
|
||||||
|
@ -321,7 +319,7 @@ func (h *vaultHook) deriveVaultToken() (token string, exit bool) {
|
||||||
|
|
||||||
// writeToken writes the given token to disk
|
// writeToken writes the given token to disk
|
||||||
func (h *vaultHook) writeToken(token string) error {
|
func (h *vaultHook) writeToken(token string) error {
|
||||||
if err := ioutil.WriteFile(h.tokenPath, []byte(token), 0777); err != nil {
|
if err := ioutil.WriteFile(h.tokenPath, []byte(token), 0666); err != nil {
|
||||||
return fmt.Errorf("failed to write vault token: %v", err)
|
return fmt.Errorf("failed to write vault token: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue