Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Containers resolver): properly detect Docker runtime in containers (#2781) #2786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/facter/resolvers/containers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# frozen_string_literal: true

# The Facter::Resolvers::Containers.resolve method must return either a valid container identifier (e.g., "docker", "lxc", etc.)
# or nil if no container is detected. It should not return a dummy value such as "container_other". This is critical because
# Facter::Util::Facts::Posix::VirtualDetector relies on a nil return value to continue checking other virtualization methods.
# Returning a non-nil dummy value would prematurely short-circuit these checks, leading to inaccurate detection results.

module Facter
module Resolvers
class Containers < BaseResolver
Expand All @@ -24,7 +29,8 @@ def read_cgroup(fact_name)
return unless output_cgroup

output_docker = %r{docker/(.+)}.match(output_cgroup)
output_lxc = %r{^/lxc/([^/]+)}.match(output_cgroup)
output_lxc = %r{^/lxc/([^/]+)}.match(output_cgroup)
return if output_docker.nil? && output_lxc.nil?

info, vm = extract_vm_and_info(output_docker, output_lxc)
@fact_list[:vm] = vm
Expand Down Expand Up @@ -57,8 +63,7 @@ def read_environ(fact_name)
vm = 'systemd_nspawn'
info = { 'id' => Facter::Util::FileHelper.safe_read('/etc/machine-id', nil).strip }
else
vm = 'container_other'
log.warn("Container runtime, '#{container}', is unsupported, setting to '#{vm}'")
return nil
end
@fact_list[:vm] = vm
@fact_list[:hypervisor] = { vm.to_sym => info } if vm
Expand Down