From 51f5ab825d8e45b852c48096a1b3dc3cfe665b98 Mon Sep 17 00:00:00 2001 From: Danny Canter <36526702+dcantah@users.noreply.github.com> Date: Fri, 11 Feb 2022 17:31:01 -0800 Subject: [PATCH] Cleanup 'getUserTokenInheritAnnotation' (#1294) This function used to just return a bool of whether the annotation was "true" or not which is a bit diffferent than what the name implied. Change to inheritUserTokenIsSet to be more clear. It also used to check if the annotation was set internally which shouldn't be needed as we only cared about whether it was "true" or not. If the value isn't in the map we should just get back the default value of a string which is fine for what it was being used for. Additionally moves a comment that was mistakingly directly above the function body to the top of the file. Signed-off-by: Daniel Canter --- internal/jobcontainers/jobcontainer.go | 2 +- internal/jobcontainers/oci.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/jobcontainers/jobcontainer.go b/internal/jobcontainers/jobcontainer.go index d1be8635fa..706d4b8cea 100644 --- a/internal/jobcontainers/jobcontainer.go +++ b/internal/jobcontainers/jobcontainer.go @@ -206,7 +206,7 @@ func (c *JobContainer) CreateProcess(ctx context.Context, config interface{}) (_ } var token windows.Token - if getUserTokenInheritAnnotation(c.spec.Annotations) { + if inheritUserTokenIsSet(c.spec.Annotations) { token, err = openCurrentProcessToken() if err != nil { return nil, err diff --git a/internal/jobcontainers/oci.go b/internal/jobcontainers/oci.go index adb5815ca3..da01236ae9 100644 --- a/internal/jobcontainers/oci.go +++ b/internal/jobcontainers/oci.go @@ -12,13 +12,14 @@ import ( specs "github.com/opencontainers/runtime-spec/specs-go" ) -const processorWeightMax = 10000 - // This file contains helpers for converting parts of the oci spec to useful // structures/limits to be applied to a job object. -func getUserTokenInheritAnnotation(annots map[string]string) bool { - val, ok := annots[annotations.HostProcessInheritUser] - return ok && val == "true" + +const processorWeightMax = 10000 + +// inheritUserTokenIsSet checks if the annotation that specifies whether we should inherit the token of the current process is set. +func inheritUserTokenIsSet(annots map[string]string) bool { + return annots[annotations.HostProcessInheritUser] == "true" } // Oci spec to job object limit information. Will do any conversions to job object specific values from