-
Notifications
You must be signed in to change notification settings - Fork 494
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
(FACT-3202) Add is_virtual and virtual support for crio #2574
Merged
joshcooper
merged 2 commits into
puppetlabs:main
from
lollipopman:crio-container-support
Jun 7, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Util | ||
module Linux | ||
class Proc | ||
class << self | ||
def getenv_for_pid(pid, field) | ||
path = "/proc/#{pid}/environ" | ||
lines = Facter::Util::FileHelper.safe_readlines(path, [], "\0", chomp: true) | ||
lines.each do |line| | ||
key, value = line.split('=', 2) | ||
return value if key == field | ||
end | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facter::Util::Linux::Proc do | ||
describe '#getenv_for_pid' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/1/environ', [], "\0", { chomp: true }) | ||
.and_return(proc_environ.readlines("\0", chomp: true)) | ||
end | ||
|
||
context 'when field exists' do | ||
let(:proc_environ) { load_fixture('proc_environ_podman') } | ||
|
||
it 'returns the field' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'container') | ||
expect(result).to eq('podman') | ||
end | ||
end | ||
|
||
context 'when field does not exist' do | ||
let(:proc_environ) { load_fixture('proc_environ_podman') } | ||
|
||
it 'returns nil' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'butter') | ||
expect(result).to eq(nil) | ||
end | ||
end | ||
|
||
context 'when field is empty' do | ||
let(:proc_environ) { load_fixture('proc_environ_no_value') } | ||
|
||
it 'returns an empty string' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'bubbles') | ||
expect(result).to eq('') | ||
end | ||
end | ||
end | ||
end |
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
/proc/1/environ
containscontainer=<value>
where<value>
is non-empty and is not one of the values in thecase
, then we setvm=container_other
and never fall back toread_cgroup
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, perhaps
read_environ()
should only log a warning and not set the value tocontainer_other
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lollipopman prior to your change, we checked
/proc/1/cgroups
fordocker
facter/lib/facter/resolvers/containers.rb
Line 39 in d47f879
And then 'lxc' or fell back to checking the
container
environment variable in/proc/1/environ
facter/lib/facter/resolvers/containers.rb
Line 42 in d47f879
Your commit reversed the order, so it looks in
/proc/1/environ
first.facter/lib/facter/resolvers/containers.rb
Line 18 in 7bc38cc
Was that intentional? Would it be a problem if I reversed it?
One thing I didn't realize when I merged this is the
VirtualDetector
callsfacter/lib/facter/util/facts/posix/virtual_detector.rb
Line 19 in d47f879
So the
Containers
resolver can't hard codecontainer_other
https://github.com/puppetlabs/facter/blob/0656d9a34ce4790129f1fd6eba5bb4d49a9b9ad1/lib/facter/resolvers/containers.rb#L60C19-L60C34There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I had a strong reason for changing the order, and my fault for not adding a comment if I did. I assume my rationale was that the environment variable was more authoritative, but I don't think that argument is very strong at present. As for the hard coding of
container_other
I agree that should be dropped and just return nil for the fact.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries @lollipopman, thanks for confirming!