diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 0f66f1c..bfbe7d7 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -110,7 +110,14 @@ func Virtualization() (string, string, error) { return VirtualizationWithContext(context.Background()) } +var virtualizationCache map[string]string = nil + func VirtualizationWithContext(ctx context.Context) (string, string, error) { + // if cached already, return from cache + if virtualizationCache != nil { + return virtualizationCache["system"], virtualizationCache["role"], nil + } + var system string var role string @@ -231,6 +238,13 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) { role = "host" } } + + // before returning for the first time, cache the system and role + virtualizationCache = map[string]string{ + "system": system, + "role": role, + } + return system, role, nil }