template: use pointer values for gid and uid (#14203)

When a Nomad agent starts and loads jobs that already existed in the
cluster, the default template uid and gid was being set to 0, since this
is the zero value for int. This caused these jobs to fail in
environments where it was not possible to use 0, such as in Windows
clients.

In order to differentiate between an explicit 0 and a template where
these properties were not set we need to use a pointer.
This commit is contained in:
Luiz Aoqui
2022-08-22 16:25:49 -04:00
committed by GitHub
parent 90c143f66b
commit 934bafb922
19 changed files with 137 additions and 63 deletions

5
jobspec2/helper_test.go Normal file
View File

@@ -0,0 +1,5 @@
package jobspec2
func intToPtr(v int) *int {
return &v
}

View File

@@ -107,12 +107,6 @@ func normalizeTemplates(templates []*api.Template) {
if t.Perms == nil {
t.Perms = stringToPtr("0644")
}
if t.Uid == nil {
t.Uid = intToPtr(-1)
}
if t.Gid == nil {
t.Gid = intToPtr(-1)
}
if t.Splay == nil {
t.Splay = durationToPtr(5 * time.Second)
}
@@ -127,10 +121,6 @@ func boolToPtr(v bool) *bool {
return &v
}
func intToPtr(v int) *int {
return &v
}
func stringToPtr(v string) *string {
return &v
}