From 8f492bca12e38b57eb7cca3282a0812cf8570a88 Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:49:52 +0100 Subject: [PATCH 1/2] drivers: fix capabilities on non-linux systems --- drivers/shared/capabilities/defaults.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/shared/capabilities/defaults.go b/drivers/shared/capabilities/defaults.go index 6323590a7a8..4c7c2c59898 100644 --- a/drivers/shared/capabilities/defaults.go +++ b/drivers/shared/capabilities/defaults.go @@ -6,6 +6,7 @@ package capabilities import ( "fmt" "regexp" + "runtime" "github.com/moby/sys/capability" ) @@ -41,6 +42,13 @@ func Supported() *Set { s := New(nil) list, _ := capability.ListSupported() + + // capability.ListSupported() will always return an empty list on non-linux + // systems + if runtime.GOOS != "linux" { + list = capability.ListKnown() + } + // accumulate every capability supported by this system for _, c := range list { s.Add(c.String()) From f0143db99c2b4322f0f7a8ceaf2105673ac68a0d Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:15:46 +0100 Subject: [PATCH 2/2] more elegant? --- drivers/shared/capabilities/defaults.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/shared/capabilities/defaults.go b/drivers/shared/capabilities/defaults.go index 4c7c2c59898..b86d7aacf98 100644 --- a/drivers/shared/capabilities/defaults.go +++ b/drivers/shared/capabilities/defaults.go @@ -41,11 +41,14 @@ func NomadDefaults() *Set { func Supported() *Set { s := New(nil) - list, _ := capability.ListSupported() - - // capability.ListSupported() will always return an empty list on non-linux - // systems - if runtime.GOOS != "linux" { + var list []capability.Cap + + switch runtime.GOOS { + case "linux": + list, _ = capability.ListSupported() + default: + // capability.ListSupported() will always return an empty list on + // non-linux systems list = capability.ListKnown() }