From 4b14b5b90c6bddc0f0418c6fb4c4d4459adc51b8 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 26 Jan 2023 18:08:02 -0500 Subject: [PATCH 1/2] template: restore driver handle on update When the template hook Update() method is called it may recreate the template manager if the Nomad or Vault token has been updated. This caused the new template manager did not have a driver handler because this was only being set on the Poststart hook, which is not called for inplace updates. --- client/allocrunner/taskrunner/template_hook.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/allocrunner/taskrunner/template_hook.go b/client/allocrunner/taskrunner/template_hook.go index 275937988e2..3151454339d 100644 --- a/client/allocrunner/taskrunner/template_hook.go +++ b/client/allocrunner/taskrunner/template_hook.go @@ -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 @@ -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 { @@ -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 } From 00f0aa77d0345cf63d2c08cbd565d0cad2959788 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 26 Jan 2023 18:13:26 -0500 Subject: [PATCH 2/2] changelog: add entry for #15915 --- .changelog/15915.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/15915.txt diff --git a/.changelog/15915.txt b/.changelog/15915.txt new file mode 100644 index 00000000000..cb6ccb4ba2c --- /dev/null +++ b/.changelog/15915.txt @@ -0,0 +1,3 @@ +```release-note:bug +template: Fixed a bug that caused the chage script to fail to run +```