Show correct default values or show none

Before this PR, the podman --help command shows the defaults
as runc and overlay even if the storage.conf and containers.conf
files do not match. This PR changes them to show the actual defaults
and in the case of storage driver, does not show the default at all.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2022-01-23 07:10:58 -05:00
parent b75d6baf07
commit 1cddd63976
3 changed files with 24 additions and 5 deletions

View File

@ -415,12 +415,12 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
_ = cmd.RegisterFlagCompletionFunc(runrootFlagName, completion.AutocompleteDefault) _ = cmd.RegisterFlagCompletionFunc(runrootFlagName, completion.AutocompleteDefault)
runtimeFlagName := "runtime" runtimeFlagName := "runtime"
pFlags.StringVar(&opts.RuntimePath, runtimeFlagName, "", "Path to the OCI-compatible binary used to run containers, default is /usr/bin/runc") pFlags.StringVar(&opts.RuntimePath, runtimeFlagName, cfg.Engine.OCIRuntime, "Path to the OCI-compatible binary used to run containers.")
_ = cmd.RegisterFlagCompletionFunc(runtimeFlagName, completion.AutocompleteDefault) _ = cmd.RegisterFlagCompletionFunc(runtimeFlagName, completion.AutocompleteDefault)
// -s is deprecated due to conflict with -s on subcommands // -s is deprecated due to conflict with -s on subcommands
storageDriverFlagName := "storage-driver" storageDriverFlagName := "storage-driver"
pFlags.StringVar(&opts.StorageDriver, storageDriverFlagName, "", "Select which storage driver is used to manage storage of images and containers (default is overlay)") pFlags.StringVar(&opts.StorageDriver, storageDriverFlagName, "", "Select which storage driver is used to manage storage of images and containers")
_ = cmd.RegisterFlagCompletionFunc(storageDriverFlagName, completion.AutocompleteNone) //TODO: what can we recommend here? _ = cmd.RegisterFlagCompletionFunc(storageDriverFlagName, completion.AutocompleteNone) //TODO: what can we recommend here?
tmpdirFlagName := "tmpdir" tmpdirFlagName := "tmpdir"

View File

@ -719,6 +719,14 @@ func SkipIfRemote(reason string) {
Skip("[remote]: " + reason) Skip("[remote]: " + reason)
} }
func SkipIfNotRemote(reason string) {
checkReason(reason)
if IsRemote() {
return
}
Skip("[local]: " + reason)
}
// SkipIfInContainer skips a test if the test is run inside a container // SkipIfInContainer skips a test if the test is run inside a container
func SkipIfInContainer(reason string) { func SkipIfInContainer(reason string) {
checkReason(reason) checkReason(reason)

View File

@ -304,9 +304,7 @@ var _ = Describe("Verify podman containers.conf usage", func() {
}) })
It("podman-remote test localcontainers.conf", func() { It("podman-remote test localcontainers.conf", func() {
if !IsRemote() { SkipIfNotRemote("this test is only for remote")
Skip("this test is only for remote")
}
os.Setenv("CONTAINERS_CONF", "config/containers-remote.conf") os.Setenv("CONTAINERS_CONF", "config/containers-remote.conf")
// Configuration that comes from remote server // Configuration that comes from remote server
@ -560,4 +558,17 @@ var _ = Describe("Verify podman containers.conf usage", func() {
inspect.WaitWithDefaultTimeout() inspect.WaitWithDefaultTimeout()
Expect(inspect.OutputToString()).To(Equal("disabled")) Expect(inspect.OutputToString()).To(Equal("disabled"))
}) })
It("podman containers.conf runtime", func() {
SkipIfRemote("--runtime option is not available for remote commands")
conffile := filepath.Join(podmanTest.TempDir, "container.conf")
err := ioutil.WriteFile(conffile, []byte("[engine]\nruntime=\"testruntime\"\n"), 0755)
Expect(err).ToNot(HaveOccurred())
os.Setenv("CONTAINERS_CONF", conffile)
result := podmanTest.Podman([]string{"--help"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring("Path to the OCI-compatible binary used to run containers. (default \"testruntime\")"))
})
}) })