Skip to content

Commit

Permalink
Add IsUserNamespaceInKernel() test environment condition
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Mountain <eric.mountain@datadoghq.com>
  • Loading branch information
EricMountain committed Dec 7, 2020
1 parent 81548d4 commit eaeb59c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions testutil/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ func (e *Execution) IsRootless() bool {
return os.Getenv("DOCKER_ROOTLESS") != ""
}

// IsUserNamespaceInKernel returns whether the kernel supports user namespaces
func (e *Execution) IsUserNamespaceInKernel() bool {
if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) {
/*
* This kernel-provided file only exists if user namespaces are
* supported
*/
return false
}

// We need extra check on redhat based distributions
if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil {
defer f.Close()
b := make([]byte, 1)
_, _ = f.Read(b)
return string(b) != "N"
}

return true
}

// HasExistingImage checks whether there is an image with the given reference.
// Note that this is done by filtering and then checking whether there were any
// results -- so ambiguous references might result in false-positives.
Expand Down

0 comments on commit eaeb59c

Please sign in to comment.