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 lxc container detection #2741

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

lollipopman
Copy link
Contributor

Commit 7bc38cc removed the regex matching for lxc, /container=lxc/, and instead matched the env var exactly, using the value lxcroot from the rspec test. However, I can find no evidence that lxc ever sets container to anything other than lxc, so change lxcroot to lxc 1.

Fixes: #2737

Commit 7bc38cc removed the regex
matching for lxc, /container=lxc/, and instead matched the env var
exactly, using the value lxcroot from the rspec test. However, I can
find no evidence that lxc ever sets container to anything other than
lxc, so change lxcroot to lxc [1][2].

[1]: https://codesearch.debian.net/search?q=container%3Dlxc&literal=1
[2]: https://github.com/search?q=container%3Dlxcroot&type=code

Fixes: puppetlabs#2737
@lollipopman lollipopman requested a review from a team as a code owner July 29, 2024 21:00
@puppetlabs-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@joshcooper
Copy link
Contributor

I was able to reproduce the problem:

$ sudo lxc-create --name mycontainer --template download -- --dist almalinux --release 9 --arch amd64
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created a Almalinux 9 x86_64 (20240730_23:08) container.

$ sudo lxc-start --name mycontainer
$ sudo  lxc-attach --name mycontainer
[root@mycontainer /]# yum install ruby
Last metadata expiration check: 0:00:06 ago on Wed 31 Jul 2024 06:10:07 PM UTC.
Dependencies resolved.
==============================================================================================================================================================
 Package                                    Architecture                   Version                                    Repository                         Size
==============================================================================================================================================================
Installing:
 ruby                                       x86_64                         3.0.7-162.el9_4                            appstream                          38 k
Installing dependencies:
 ruby-libs                                  x86_64                         3.0.7-162.el9_4                            appstream                         3.2 M
 rubygem-json                               x86_64                         2.5.1-162.el9_4                            appstream                          51 k
 rubygem-psych                              x86_64                         3.3.2-162.el9_4                            appstream                          48 k
Installing weak dependencies:
 ruby-default-gems                          noarch                         3.0.7-162.el9_4                            appstream                          29 k
 rubygem-bigdecimal                         x86_64                         3.0.0-162.el9_4                            appstream                          51 k
 rubygem-bundler                            noarch                         2.2.33-162.el9_4                           appstream                         369 k
 rubygem-io-console                         x86_64                         0.5.7-162.el9_4                            appstream                          22 k
 rubygem-rdoc                               noarch                         6.3.4.1-162.el9_4                          appstream                         398 k
 rubygems                                   noarch                         3.2.33-162.el9_4                           appstream                         253 k

Transaction Summary
==============================================================================================================================================================
Install  10 Packages

Total download size: 4.4 M
Installed size: 16 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): ruby-default-gems-3.0.7-162.el9_4.noarch.rpm                                                                          527 kB/s |  29 kB     00:00    
(2/10): ruby-3.0.7-162.el9_4.x86_64.rpm                                                                                       604 kB/s |  38 kB     00:00    
(3/10): rubygem-bigdecimal-3.0.0-162.el9_4.x86_64.rpm                                                                         2.4 MB/s |  51 kB     00:00    
(4/10): rubygem-io-console-0.5.7-162.el9_4.x86_64.rpm                                                                         697 kB/s |  22 kB     00:00    
(5/10): rubygem-bundler-2.2.33-162.el9_4.noarch.rpm                                                                           6.7 MB/s | 369 kB     00:00    
(6/10): ruby-libs-3.0.7-162.el9_4.x86_64.rpm                                                                                   25 MB/s | 3.2 MB     00:00    
(7/10): rubygem-json-2.5.1-162.el9_4.x86_64.rpm                                                                               1.2 MB/s |  51 kB     00:00    
(8/10): rubygem-psych-3.3.2-162.el9_4.x86_64.rpm                                                                              1.1 MB/s |  48 kB     00:00    
(9/10): rubygem-rdoc-6.3.4.1-162.el9_4.noarch.rpm                                                                             4.6 MB/s | 398 kB     00:00    
(10/10): rubygems-3.2.33-162.el9_4.noarch.rpm                                                                                 2.7 MB/s | 253 kB     00:00    
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                         7.8 MB/s | 4.4 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                      1/1 
  Installing       : ruby-libs-3.0.7-162.el9_4.x86_64                                                                                                    1/10 
  Installing       : rubygem-bigdecimal-3.0.0-162.el9_4.x86_64                                                                                           2/10 
  Installing       : ruby-default-gems-3.0.7-162.el9_4.noarch                                                                                            3/10 
  Installing       : rubygem-bundler-2.2.33-162.el9_4.noarch                                                                                             4/10 
  Installing       : rubygem-io-console-0.5.7-162.el9_4.x86_64                                                                                           5/10 
  Installing       : rubygem-json-2.5.1-162.el9_4.x86_64                                                                                                 6/10 
  Installing       : rubygem-psych-3.3.2-162.el9_4.x86_64                                                                                                7/10 
  Installing       : rubygem-rdoc-6.3.4.1-162.el9_4.noarch                                                                                               8/10 
  Installing       : rubygems-3.2.33-162.el9_4.noarch                                                                                                    9/10 
  Installing       : ruby-3.0.7-162.el9_4.x86_64                                                                                                        10/10 
  Running scriptlet: ruby-3.0.7-162.el9_4.x86_64                                                                                                        10/10 
  Verifying        : ruby-3.0.7-162.el9_4.x86_64                                                                                                         1/10 
  Verifying        : ruby-default-gems-3.0.7-162.el9_4.noarch                                                                                            2/10 
  Verifying        : ruby-libs-3.0.7-162.el9_4.x86_64                                                                                                    3/10 
  Verifying        : rubygem-bigdecimal-3.0.0-162.el9_4.x86_64                                                                                           4/10 
  Verifying        : rubygem-bundler-2.2.33-162.el9_4.noarch                                                                                             5/10 
  Verifying        : rubygem-io-console-0.5.7-162.el9_4.x86_64                                                                                           6/10 
  Verifying        : rubygem-json-2.5.1-162.el9_4.x86_64                                                                                                 7/10 
  Verifying        : rubygem-psych-3.3.2-162.el9_4.x86_64                                                                                                8/10 
  Verifying        : rubygem-rdoc-6.3.4.1-162.el9_4.noarch                                                                                               9/10 
  Verifying        : rubygems-3.2.33-162.el9_4.noarch                                                                                                   10/10 

Installed:
  ruby-3.0.7-162.el9_4.x86_64                         ruby-default-gems-3.0.7-162.el9_4.noarch           ruby-libs-3.0.7-162.el9_4.x86_64                   
  rubygem-bigdecimal-3.0.0-162.el9_4.x86_64           rubygem-bundler-2.2.33-162.el9_4.noarch            rubygem-io-console-0.5.7-162.el9_4.x86_64          
  rubygem-json-2.5.1-162.el9_4.x86_64                 rubygem-psych-3.3.2-162.el9_4.x86_64               rubygem-rdoc-6.3.4.1-162.el9_4.noarch              
  rubygems-3.2.33-162.el9_4.noarch                   

Complete!
[root@mycontainer /]# gem install facter
Fetching thor-1.2.2.gem
Successfully installed thor-1.2.2
Fetching hocon-1.4.0.gem
Successfully installed hocon-1.4.0
Fetching facter-4.8.0.gem
Successfully installed facter-4.8.0
Parsing documentation for thor-1.2.2
Installing ri documentation for thor-1.2.2
Parsing documentation for hocon-1.4.0
Installing ri documentation for hocon-1.4.0
Parsing documentation for facter-4.8.0
Installing ri documentation for facter-4.8.0
Done installing documentation for thor, hocon, facter after 2 seconds
3 gems installed
[root@mycontainer /]# facter virtual
[2024-07-31 18:10:28.426753 ] WARN Facter::Resolvers::Containers - Container runtime, 'lxc', is unsupported, setting to, 'container_other' 
container_other

I applied the patch to the lib dir and it corrected the issue:

[root@mycontainer /]# patch -p1 -d /usr/local/share/gems/gems/facter-4.8.0/ < 2741.patch 
patching file lib/facter/resolvers/containers.rb
[root@mycontainer /]# facter virtual
lxc

@joshcooper joshcooper merged commit e776b42 into puppetlabs:main Jul 31, 2024
18 checks passed
@AriaXLi AriaXLi added the bug Something isn't working label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsupported container runtime 'lxc' with facter 4.8.0+ / nightly
4 participants