Skip to content

Check that docker_version is not nil before using it #770

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

Closed
Closed
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
18 changes: 9 additions & 9 deletions lib/facter/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def interfaces
Facter.add(:docker_version) do
setcode do
if Facter::Core::Execution.which('docker')
value = Facter::Core::Execution.exec(
"#{docker_command} version --format '{{json .}}'", timeout: 90
value = Facter::Core::Execution.execute(
"#{docker_command} version --format '{{json .}}'", options: {limit: 90}
Copy link
Contributor Author

@johanfleury johanfleury Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone who knows ruby confirm that this is how to do it? Whatever I pass as parameter to this function is accepted.

Also, while facter’s doc says the option is called time_limit, it seems to actually be called limit in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the documentation is right and it's a bug in the code, I'll open a PR to address this :-)

There are a few more issues. I opened #773 to address them.

)
val = JSON.parse(value)
end
Expand All @@ -80,7 +80,7 @@ def interfaces
Facter.add(:docker_worker_join_token) do
setcode do
if Facter::Util::Resolution.which('docker')
val = Facter::Util::Resolution.exec(
val = Facter::Util::Resolution.execute(
"#{docker_command} swarm join-token worker -q",
)
end
Expand All @@ -91,7 +91,7 @@ def interfaces
Facter.add(:docker_manager_join_token) do
setcode do
if Facter::Util::Resolution.which('docker')
val = Facter::Util::Resolution.exec(
val = Facter::Util::Resolution.execute(
"#{docker_command} swarm join-token manager -q",
)
end
Expand All @@ -102,23 +102,23 @@ def interfaces
Facter.add(:docker) do
setcode do
docker_version = Facter.value(:docker_client_version)
if docker_version.match?(%r{1[0-9][0-2]?[.]\w+})
if docker_version && docker_version.match?(%r{1[0-9][0-2]?[.]\w+})
if Facter::Core::Execution.which('docker')
docker_json_str = Facter::Core::Execution.exec(
"#{docker_command} info --format '{{json .}}'", timeout: 90
docker_json_str = Facter::Core::Execution.execute(
"#{docker_command} info --format '{{json .}}'", options: {limit: 90}
)
begin
docker = JSON.parse(docker_json_str)
docker['network'] = {}

docker['network']['managed_interfaces'] = {}
network_list = Facter::Core::Execution.exec("#{docker_command} network ls | tail -n +2", timeout: 90)
network_list = Facter::Core::Execution.execute("#{docker_command} network ls | tail -n +2", options: {limit: 90})
docker_network_names = []
network_list.each_line { |line| docker_network_names.push line.split[1] }
docker_network_ids = []
network_list.each_line { |line| docker_network_ids.push line.split[0] }
docker_network_names.each do |network|
inspect = JSON.parse(Facter::Core::Execution.exec("#{docker_command} network inspect #{network}", timeout: 90))
inspect = JSON.parse(Facter::Core::Execution.execute("#{docker_command} network inspect #{network}", options: {limit: 90}))
docker['network'][network] = inspect[0]
network_id = docker['network'][network]['Id'][0..11]
interfaces.each do |iface|
Expand Down