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 1 commit
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
18 changes: 14 additions & 4 deletions lib/facter/resolvers/containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ class << self

def post_resolve(fact_name, _options)
@fact_list.fetch(fact_name) do
read_environ(fact_name) || read_cgroup(fact_name)
environ_result = read_environ(fact_name)
cgroup_result = read_cgroup(fact_name)

if environ_result.nil? && cgroup_result.nil?
@fact_list[:vm] = 'container_other'
@fact_list[:hypervisor] = ''
log.warn("Container runtime is unsupported, setting to 'container_other'")
@fact_list[fact_name]
else
environ_result || cgroup_result
end
end
end

Expand All @@ -24,7 +34,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 +68,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
Loading