Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template: restore driver handle on update #15915

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/15915.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
template: Fixed a bug that caused the chage script to fail to run
```
12 changes: 11 additions & 1 deletion client/allocrunner/taskrunner/template_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ type templateHook struct {
templateManager *template.TaskTemplateManager
managerLock sync.Mutex

// driverHandle is the task driver executor used by the template manager to
// run scripts when the template change mode is set to script.
//
// Must obtain a managerLock before changing. It may be nil.
driverHandle ti.ScriptExecutor

// consulNamespace is the current Consul namespace
consulNamespace string

Expand Down Expand Up @@ -124,7 +130,8 @@ func (h *templateHook) Poststart(ctx context.Context, req *interfaces.TaskPostst
}

if req.DriverExec != nil {
h.templateManager.SetDriverHandle(req.DriverExec)
h.driverHandle = req.DriverExec
h.templateManager.SetDriverHandle(h.driverHandle)
} else {
for _, tmpl := range h.config.templates {
if tmpl.ChangeMode == structs.TemplateChangeModeScript {
Expand Down Expand Up @@ -158,6 +165,9 @@ func (h *templateHook) newManager() (unblock chan struct{}, err error) {
}

h.templateManager = m
if h.driverHandle != nil {
h.templateManager.SetDriverHandle(h.driverHandle)
}
return unblock, nil
}

Expand Down