Skip to content

Commit 55585de

Browse files
Merge pull request #2499 from Luap99/config-dropin
pkg/config: rework testing and add new containers.rootless.conf search location
2 parents 59e7619 + 527d275 commit 55585de

15 files changed

+364
-242
lines changed

docs/containers.conf.5.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ a TOML format that can be easily modified and versioned.
1111

1212
Container engines read the __/usr/share/containers/containers.conf__,
1313
__/etc/containers/containers.conf__, and __/etc/containers/containers.conf.d/\*.conf__
14-
for global configuration that effects all users.
14+
for global configuration that affects all users.
15+
For global configuration that only affects rootless users use __/etc/containers/containers.rootless.conf__,
16+
__/etc/containers/containers.rootless.d/\*.conf__ and __/etc/containers/containers.rootless.d/\$UID/\*.conf__. The UID is the user's uid which podman runs under so it can be used to specify a certain config for only a single user without having to put the config into the user's home directory.
1517
For user specific configuration it reads __\$XDG_CONFIG_HOME/containers/containers.conf__ and
1618
__\$XDG_CONFIG_HOME/containers/containers.conf.d/\*.conf__ files. When `$XDG_CONFIG_HOME` is not set it falls back to using `$HOME/.config` instead.
1719

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
)
2222

2323
const (
24-
// UserOverrideContainersConfig holds the containers config path overridden by the rootless user
25-
UserOverrideContainersConfig = ".config/" + _configPath
24+
// userOverrideContainersConfig holds the containers config path overridden by the rootless user.
25+
userOverrideContainersConfig = ".config/" + _configPath
2626
// Token prefix for looking for helper binary under $BINDIR
2727
bindirPrefix = "$BINDIR"
2828
)

pkg/config/config_bsd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
package config
44

55
const (
6-
// OverrideContainersConfig holds the default config path overridden by the root user
7-
OverrideContainersConfig = "/usr/local/etc/" + _configPath
6+
// overrideContainersConfig holds the default config path overridden by the root user.
7+
overrideContainersConfig = "/usr/local/etc/" + _configPath
88

9-
// DefaultContainersConfig holds the default containers config path
10-
DefaultContainersConfig = "/usr/local/share/" + _configPath
9+
// defaultContainersConfig holds the default containers config path.
10+
defaultContainersConfig = "/usr/local/share/" + _configPath
1111

1212
// DefaultSignaturePolicyPath is the default value for the
1313
// policy.json file.

pkg/config/config_darwin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package config
22

33
const (
4-
// OverrideContainersConfig holds the default config path overridden by the root user
5-
OverrideContainersConfig = "/etc/" + _configPath
4+
// overrideContainersConfig holds the default config path overridden by the root user.
5+
overrideContainersConfig = "/etc/" + _configPath
66

7-
// DefaultContainersConfig holds the default containers config path
8-
DefaultContainersConfig = "/usr/share/" + _configPath
7+
// defaultContainersConfig holds the default containers config path.
8+
defaultContainersConfig = "/usr/share/" + _configPath
99

1010
// DefaultSignaturePolicyPath is the default value for the
1111
// policy.json file.

pkg/config/config_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
)
77

88
const (
9-
// OverrideContainersConfig holds the default config path overridden by the root user
10-
OverrideContainersConfig = "/etc/" + _configPath
9+
// overrideContainersConfig holds the default config path overridden by the root user.
10+
overrideContainersConfig = "/etc/" + _configPath
1111

12-
// DefaultContainersConfig holds the default containers config path
13-
DefaultContainersConfig = "/usr/share/" + _configPath
12+
// defaultContainersConfig holds the default containers config path.
13+
defaultContainersConfig = "/usr/share/" + _configPath
1414

1515
// DefaultSignaturePolicyPath is the default value for the
1616
// policy.json file.

pkg/config/config_local_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var _ = Describe("Config Local", func() {
9090
})
9191

9292
It("parse network subnet pool", func() {
93-
config, err := NewConfig("testdata/containers_default.conf")
93+
config, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
9494
// Then
9595
gomega.Expect(err).ToNot(gomega.HaveOccurred())
9696
net1, _ := types.ParseCIDR("10.89.0.0/16")
@@ -108,47 +108,47 @@ var _ = Describe("Config Local", func() {
108108

109109
It("parse dns port", func() {
110110
// Given
111-
config, err := New(nil)
111+
config, err := newLocked(&Options{}, &paths{})
112112
gomega.Expect(err).ToNot(gomega.HaveOccurred())
113113
gomega.Expect(config.Network.DNSBindPort).To(gomega.Equal(uint16(0)))
114114
// When
115-
config2, err := NewConfig("testdata/containers_default.conf")
115+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
116116
// Then
117117
gomega.Expect(err).ToNot(gomega.HaveOccurred())
118118
gomega.Expect(config2.Network.DNSBindPort).To(gomega.Equal(uint16(1153)))
119119
})
120120

121121
It("test firewall", func() {
122122
// Given
123-
config, err := New(nil)
123+
config, err := newLocked(&Options{}, &paths{})
124124
gomega.Expect(err).ToNot(gomega.HaveOccurred())
125125
gomega.Expect(config.Network.FirewallDriver).To(gomega.Equal(string("")))
126126
// When
127-
config2, err := NewConfig("testdata/containers_default.conf")
127+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
128128
// Then
129129
gomega.Expect(err).ToNot(gomega.HaveOccurred())
130130
gomega.Expect(config2.Network.FirewallDriver).To(gomega.Equal("none"))
131131
})
132132

133133
It("parse pasta_options", func() {
134134
// Given
135-
config, err := New(nil)
135+
config, err := newLocked(&Options{}, &paths{})
136136
gomega.Expect(err).ToNot(gomega.HaveOccurred())
137137
gomega.Expect(config.Network.PastaOptions.Get()).To(gomega.BeEmpty())
138138
// When
139-
config2, err := NewConfig("testdata/containers_default.conf")
139+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
140140
// Then
141141
gomega.Expect(err).ToNot(gomega.HaveOccurred())
142142
gomega.Expect(config2.Network.PastaOptions.Get()).To(gomega.Equal([]string{"-t", "auto"}))
143143
})
144144

145145
It("parse default_rootless_network_cmd", func() {
146146
// Given
147-
config, err := NewConfig("")
147+
config, err := newLocked(&Options{}, &paths{})
148148
gomega.Expect(err).ToNot(gomega.HaveOccurred())
149149
gomega.Expect(config.Network.DefaultRootlessNetworkCmd).To(gomega.Equal("pasta"))
150150
// When
151-
config2, err := NewConfig("testdata/containers_default.conf")
151+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
152152
// Then
153153
gomega.Expect(err).ToNot(gomega.HaveOccurred())
154154
gomega.Expect(config2.Network.DefaultRootlessNetworkCmd).To(gomega.Equal("slirp4netns"))
@@ -338,7 +338,7 @@ var _ = Describe("Config Local", func() {
338338
// Given
339339
expectedEnv := []string{"super=duper", "foo=bar"}
340340
// When
341-
config, err := NewConfig("testdata/containers_default.conf")
341+
config, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
342342
// Then
343343
gomega.Expect(err).ToNot(gomega.HaveOccurred())
344344
gomega.Expect(config.Engine.Env.Get()).To(gomega.BeEquivalentTo(expectedEnv))
@@ -348,25 +348,25 @@ var _ = Describe("Config Local", func() {
348348

349349
It("should override cdi_spec_dirs if provided", func() {
350350
// Given
351-
config1, err := New(nil)
351+
config1, err := newLocked(&Options{}, &paths{})
352352
// Then
353353
gomega.Expect(err).ToNot(gomega.HaveOccurred())
354354
gomega.Expect(config1.Engine.CdiSpecDirs.Get()).To(gomega.Equal([]string{"/etc/cdi", "/var/run/cdi"}))
355355

356356
// Given default just get default
357-
config2, err := NewConfig("testdata/containers_default.conf")
357+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
358358
// Then
359359
gomega.Expect(err).ToNot(gomega.HaveOccurred())
360360
gomega.Expect(config2.Engine.CdiSpecDirs.Get()).To(gomega.Equal([]string{"/etc/cdi", "/var/run/cdi"}))
361361

362362
// Given override just get override
363-
config3, err := NewConfig("testdata/containers_override.conf")
363+
config3, err := newLocked(&Options{}, &paths{etc: "testdata/containers_override.conf"})
364364
// Then
365365
gomega.Expect(err).ToNot(gomega.HaveOccurred())
366366
gomega.Expect(config3.Engine.CdiSpecDirs.Get()).To(gomega.Equal([]string{"/somepath"}))
367367

368368
// Given override just get override
369-
config4, err := NewConfig("testdata/containers_override2.conf")
369+
config4, err := newLocked(&Options{}, &paths{etc: "testdata/containers_override2.conf"})
370370
// Then
371371
gomega.Expect(err).ToNot(gomega.HaveOccurred())
372372
gomega.Expect(config4.Engine.CdiSpecDirs.Get()).To(gomega.Equal([]string{"/somepath", "/some_other_path"}))
@@ -375,7 +375,7 @@ var _ = Describe("Config Local", func() {
375375
It("Expect Remote to be False", func() {
376376
// Given
377377
// When
378-
config, err := New(nil)
378+
config, err := newLocked(&Options{}, &paths{})
379379
// Then
380380
gomega.Expect(err).ToNot(gomega.HaveOccurred())
381381
gomega.Expect(config.Engine.Remote).To(gomega.BeFalse())
@@ -390,7 +390,7 @@ var _ = Describe("Config Local", func() {
390390
t.Setenv(containersConfEnv, "/dev/null")
391391

392392
// When
393-
config, err := New(nil)
393+
config, err := newLocked(&Options{}, &paths{})
394394

395395
// Then
396396
gomega.Expect(err).ToNot(gomega.HaveOccurred())
@@ -412,15 +412,15 @@ var _ = Describe("Config Local", func() {
412412
It("Default Umask", func() {
413413
// Given
414414
// When
415-
config, err := New(nil)
415+
config, err := newLocked(&Options{}, &paths{})
416416
// Then
417417
gomega.Expect(err).ToNot(gomega.HaveOccurred())
418418
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0022"))
419419
})
420420
It("Set Umask", func() {
421421
// Given
422422
// When
423-
config, err := NewConfig("testdata/containers_default.conf")
423+
config, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
424424
// Then
425425
gomega.Expect(err).ToNot(gomega.HaveOccurred())
426426
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0002"))
@@ -442,11 +442,11 @@ var _ = Describe("Config Local", func() {
442442

443443
It("default netns", func() {
444444
// Given
445-
config, err := New(nil)
445+
config, err := newLocked(&Options{}, &paths{})
446446
gomega.Expect(err).ToNot(gomega.HaveOccurred())
447447
gomega.Expect(config.Containers.NetNS).To(gomega.Equal("private"))
448448
// When
449-
config2, err := NewConfig("testdata/containers_default.conf")
449+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
450450
// Then
451451
gomega.Expect(err).ToNot(gomega.HaveOccurred())
452452
gomega.Expect(config2.Containers.NetNS).To(gomega.Equal("bridge"))
@@ -456,7 +456,7 @@ var _ = Describe("Config Local", func() {
456456
// Given
457457
path := ""
458458
// When
459-
config, err := NewConfig(path)
459+
config, err := newLocked(&Options{}, &paths{etc: path})
460460
gomega.Expect(err).ToNot(gomega.HaveOccurred())
461461
// Then
462462
gomega.Expect(config.Secrets.Driver).To(gomega.Equal("file"))
@@ -466,7 +466,7 @@ var _ = Describe("Config Local", func() {
466466
// Given
467467
path := "testdata/containers_override.conf"
468468
// When
469-
config, err := NewConfig(path)
469+
config, err := newLocked(&Options{}, &paths{etc: path})
470470
gomega.Expect(err).ToNot(gomega.HaveOccurred())
471471
// Then
472472
gomega.Expect(config.Secrets.Driver).To(gomega.Equal("pass"))
@@ -478,11 +478,11 @@ var _ = Describe("Config Local", func() {
478478

479479
It("Set machine image path", func() {
480480
// Given
481-
config, err := New(nil)
481+
config, err := newLocked(&Options{}, &paths{})
482482
gomega.Expect(err).ToNot(gomega.HaveOccurred())
483483
gomega.Expect(config.Machine.Image).To(gomega.Equal(""))
484484
// When
485-
config2, err := NewConfig("testdata/containers_default.conf")
485+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
486486
// Then
487487
gomega.Expect(err).ToNot(gomega.HaveOccurred())
488488
path := "https://example.com/$OS/$ARCH/foobar.ami"
@@ -493,59 +493,59 @@ var _ = Describe("Config Local", func() {
493493

494494
It("CompatAPIEnforceDockerHub", func() {
495495
// Given
496-
config, err := New(nil)
496+
config, err := newLocked(&Options{}, &paths{})
497497
gomega.Expect(err).ToNot(gomega.HaveOccurred())
498498
gomega.Expect(config.Engine.CompatAPIEnforceDockerHub).To(gomega.BeTrue())
499499
// When
500-
config2, err := NewConfig("testdata/containers_default.conf")
500+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
501501
// Then
502502
gomega.Expect(err).ToNot(gomega.HaveOccurred())
503503
gomega.Expect(config2.Engine.CompatAPIEnforceDockerHub).To(gomega.BeFalse())
504504
})
505505

506506
It("ComposeProviders", func() {
507507
// Given
508-
config, err := New(nil)
508+
config, err := newLocked(&Options{}, &paths{})
509509
gomega.Expect(err).ToNot(gomega.HaveOccurred())
510510
gomega.Expect(config.Engine.ComposeProviders.Get()).To(gomega.Equal(getDefaultComposeProviders())) // no hard-coding to work on all platforms
511511
// When
512-
config2, err := NewConfig("testdata/containers_default.conf")
512+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
513513
// Then
514514
gomega.Expect(err).ToNot(gomega.HaveOccurred())
515515
gomega.Expect(config2.Engine.ComposeProviders.Get()).To(gomega.Equal([]string{"/some/thing/else", "/than/before"}))
516516
})
517517

518518
It("AddCompression", func() {
519519
// Given
520-
config, err := New(nil)
520+
config, err := newLocked(&Options{}, &paths{})
521521
gomega.Expect(err).ToNot(gomega.HaveOccurred())
522522
gomega.Expect(config.Engine.AddCompression.Get()).To(gomega.BeEmpty()) // no hard-coding to work on all platforms
523523
// When
524-
config2, err := NewConfig("testdata/containers_default.conf")
524+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
525525
// Then
526526
gomega.Expect(err).ToNot(gomega.HaveOccurred())
527527
gomega.Expect(config2.Engine.AddCompression.Get()).To(gomega.Equal([]string{"zstd", "zstd:chunked"}))
528528
})
529529

530530
It("ComposeWarningLogs", func() {
531531
// Given
532-
config, err := New(nil)
532+
config, err := newLocked(&Options{}, &paths{})
533533
gomega.Expect(err).ToNot(gomega.HaveOccurred())
534534
gomega.Expect(config.Engine.ComposeWarningLogs).To(gomega.BeTrue())
535535
// When
536-
config2, err := NewConfig("testdata/containers_default.conf")
536+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
537537
// Then
538538
gomega.Expect(err).ToNot(gomega.HaveOccurred())
539539
gomega.Expect(config2.Engine.ComposeWarningLogs).To(gomega.BeFalse())
540540
})
541541

542542
It("Set machine disk", func() {
543543
// Given
544-
config, err := New(nil)
544+
config, err := newLocked(&Options{}, &paths{})
545545
gomega.Expect(err).ToNot(gomega.HaveOccurred())
546546
gomega.Expect(config.Machine.DiskSize).To(gomega.Equal(uint64(100)))
547547
// When
548-
config2, err := NewConfig("testdata/containers_default.conf")
548+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
549549
// Then
550550
gomega.Expect(err).ToNot(gomega.HaveOccurred())
551551
gomega.Expect(config2.Machine.DiskSize).To(gomega.Equal(uint64(20)))
@@ -557,33 +557,33 @@ var _ = Describe("Config Local", func() {
557557
cpus = 1
558558
}
559559

560-
config, err := New(nil)
560+
config, err := newLocked(&Options{}, &paths{})
561561
gomega.Expect(err).ToNot(gomega.HaveOccurred())
562562
gomega.Expect(config.Machine.CPUs).To(gomega.Equal(uint64(cpus)))
563563
// When
564-
config2, err := NewConfig("testdata/containers_default.conf")
564+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
565565
// Then
566566
gomega.Expect(err).ToNot(gomega.HaveOccurred())
567567
gomega.Expect(config2.Machine.CPUs).To(gomega.Equal(uint64(1)))
568568
})
569569
It("Set machine memory", func() {
570570
// Given
571-
config, err := New(nil)
571+
config, err := newLocked(&Options{}, &paths{})
572572
gomega.Expect(err).ToNot(gomega.HaveOccurred())
573573
gomega.Expect(config.Machine.Memory).To(gomega.Equal(uint64(2048)))
574574
// When
575-
config2, err := NewConfig("testdata/containers_default.conf")
575+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
576576
// Then
577577
gomega.Expect(err).ToNot(gomega.HaveOccurred())
578578
gomega.Expect(config2.Machine.Memory).To(gomega.Equal(uint64(1024)))
579579
})
580580
It("Get Rosetta value", func() {
581581
// Given
582-
config, err := New(nil)
582+
config, err := newLocked(&Options{}, &paths{})
583583
gomega.Expect(err).ToNot(gomega.HaveOccurred())
584584
gomega.Expect(config.Machine.Rosetta).To(gomega.BeTrue())
585585
// When
586-
config2, err := NewConfig("testdata/containers_default.conf")
586+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
587587
// Then
588588
gomega.Expect(err).ToNot(gomega.HaveOccurred())
589589
gomega.Expect(config2.Machine.Rosetta).To(gomega.BeFalse())

pkg/config/config_remote_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var _ = Describe("Config Remote", func() {
100100
It("Expect Remote to be true", func() {
101101
// Given
102102
// When
103-
config, err := New(nil)
103+
config, err := newLocked(&Options{}, &paths{})
104104
// Then
105105
gomega.Expect(err).To(gomega.BeNil())
106106
gomega.Expect(config.Engine.Remote).To(gomega.BeTrue())

0 commit comments

Comments
 (0)