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

Allow configuration of podmansh #1993

Merged
merged 1 commit into from
May 22, 2024

Conversation

grisu48
Copy link
Contributor

@grisu48 grisu48 commented May 13, 2024

Adds a new configuration section podmansh to configure the shell,
container and the timeout for podmansh.

See containers/podman#22683 for more context.

@rhatdan
Copy link
Member

rhatdan commented May 13, 2024

@lsm5 @bachradsusi PTAL

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Needs documentation and basic unit tests.

I like to see some proper design on why these option are required. For example why not just link /bin/sh to your actual shell?

Second, if we agree that we needs these options then should we move the existing PodmanShTimeout option to the new table to better group these options. We can still support the old option for backwards compat.

pkg/config/config.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented May 13, 2024

I agree lets create a
[podmansh]
Section of the containers.conf

@grisu48
Copy link
Contributor Author

grisu48 commented May 14, 2024

Needs documentation and basic unit tests.

Agreed.

I like to see some proper design on why these option are required. For example why not just link /bin/sh to your actual shell?

There are cases in which people might need to have /bin/sh and /bin/bash, e.g. when they run a distribution with shell scripts that for some reason required /bin/sh. While bash and sh are very close, there are many people out there that run a different shell on a daily basis but still require /bin/sh for running shell scripts.

If one would e.g. use a podmansh container with a fish shell as default, then linking /bin/sh to /bin/fish would likely break a good portion of the shell scripts with the #!/bin/sh shebang.
I think this motivates the configuration possibility.

I also looked into different options for achieving this: Environment variables appeared to me as a bit clumsy for this use cases and container labels are not really user-configurable options. That's what motivated a new configuration section.

Also: users can configure their own podmansh environment via $home/.config/containers/containers.conf. Allowing users to easily configure their environment is the whole point for this PR.

Second, if we agree that we needs these options then should we move the existing PodmanShTimeout option to the new table to better group these options. We can still support the old option for backwards compat.

Makes sense, will have a look.

@Luap99
Copy link
Member

Luap99 commented May 14, 2024

Thanks, yes these are good arguments for the option.

Copy link
Member

@lsm5 lsm5 left a comment

Choose a reason for hiding this comment

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

@grisu48 thanks for the PR. Agreed with @Luap99 and @rhatdan 's comments on unit test and new containers.conf section

@grisu48 grisu48 marked this pull request as draft May 15, 2024 09:32
// Shell to start in container, default: "/bin/sh"
Shell string `toml:"shell"`
// Name of the container the podmansh user should join
Container string `toml:"container"`
Copy link
Member

Choose a reason for hiding this comment

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

Add Timeout here and deprecate podmansh_timeout, and remove it from man page and containers.conf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm in the process of doing so and need input: Do we have somewhere an example value of a deprecated value? Otherwise I would keep the old value in the internal struct and use this one, if the new value is zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will use

ImageBuildFormat string `toml:"image_build_format,omitempty"`
as a template and keep the old value, while making it deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. @rhatdan @Luap99 please have a look at my suggestion.

I had to fiddle with the backwards compatability of podmansh_timeout. I wanted to have a solution, where podmansh.Timeout is preferred over the now deprecated podmansh_timeout value and the best idea I had was to use a default 0 value for both variables when they are not set. Then the newLocked function can use either of the two, if they are set and otherwise apply the default setting of 30.

This solution works, but it appears a bit clumsy. If any of you have a better idea for a more elegant solution please share.

Will work on the man page once we have resolved the remaining issues.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can leave the old default 30 on the deprecated field, then use 0 on the new one,

timeout :=  podmansh_timeout
if podmansh.Timeout > 0 {
    timeout= podmansh.Timeout
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I moved this part over to containers/podman#22683

grisu48 added a commit to grisu48/podman that referenced this pull request May 15, 2024
@rhatdan
Copy link
Member

rhatdan commented May 16, 2024

Please squash your commits and make sure they are signed. If you don't want to squash your commits, then make sure that one does not add content that a subsequent one later removes of modifies.

@@ -307,6 +307,14 @@ crun = [
"/usr/local/bin/crun",
]

[podmansh]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add a section documenting this in docs/containers.conf, removing podmansh_timeout?

**podmansh_timeout**=30
Number of seconds to wait for podmansh logins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I've also added a podmansh section therein.

Comment on lines 127 to 134
// engine.PodmanshTimeout is deprecated and should only be used, if podmansh.Timeout is not set
if config.Podmansh.Timeout == 0 {
if config.Engine.PodmanshTimeout > 0 {
config.Podmansh.Timeout = config.Engine.PodmanshTimeout
} else {
config.Podmansh.Timeout = uint(30)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I would not call this code in c/common at all, given there is only ever one user in podman that is only called in very rare cases (podmansh) I would do it there.
That way we do not have to run this for every podman command, sure it is not like this is slow but these things add up over time.

Copy link
Contributor Author

@grisu48 grisu48 May 21, 2024

Choose a reason for hiding this comment

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

I moved this part over to containers/podman#22683 which largely simplifies this code. I could remove a unit test and a test file, which makes this PR smaller 👍

@grisu48
Copy link
Contributor Author

grisu48 commented May 21, 2024

Amended, please @rhatdan @Luap99 @danishprakash could you have another look?

@grisu48 grisu48 marked this pull request as ready for review May 21, 2024 09:13
docs/containers.conf.5.md Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented May 21, 2024

I would like to see three tests satisfied.

1 engine.podman_timeout set inside of containers.conf and no setting for podmansh.timeout.
2 podmansh.timeout set no setting for engine.podman_timeout
3 Both set.

It would be nice to have a config.PodmanshTimeout() function which gives you the right setting with the three examples above. This would allow podmansh to just call the function.

@grisu48
Copy link
Contributor Author

grisu48 commented May 21, 2024

I would like to see three tests satisfied.

1 engine.podman_timeout set inside of containers.conf and no setting for podmansh.timeout. 2 podmansh.timeout set no setting for engine.podman_timeout 3 Both set.

It would be nice to have a config.PodmanshTimeout() function which gives you the right setting with the three examples above. This would allow podmansh to just call the function.

Done.

This happens in two tests: We check if podman reads the engine.podmansh_timeout and podmansh.timeout settings from the config files and the new "Check podmansh timeout settings" unit test checks if the PodmanshTimeout() method behaves according to the three cases you requested.

I think this should satisfy your request.

@grisu48 grisu48 marked this pull request as ready for review May 21, 2024 12:31
pkg/config/config.go Outdated Show resolved Hide resolved
@lsm5
Copy link
Member

lsm5 commented May 21, 2024

LGTM pending validate tests.

@TomSweeneyRedHat
Copy link
Member

LGTM once the one spelling error is corrected to allow the tests to complete. Slapping a 5.1 label on this, we'd like to get this merged ASAP so we can add it to Podman v5.1

pkg/config/containers.conf Outdated Show resolved Hide resolved
pkg/config/containers.conf Outdated Show resolved Hide resolved
pkg/config/containers.conf Outdated Show resolved Hide resolved
docs/containers.conf.5.md Outdated Show resolved Hide resolved
Adds a new configuration section `podmansh` to configure the shell,
container and the timeout for podmansh.

Signed-off-by: phoenix <felix.niederwanger@suse.com>
@grisu48
Copy link
Contributor Author

grisu48 commented May 22, 2024

Incorporated the latest suggestions and amended the PR.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented May 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grisu48, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Luap99
Copy link
Member

Luap99 commented May 22, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label May 22, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 1a97fd1 into containers:main May 22, 2024
12 checks passed
@grisu48
Copy link
Contributor Author

grisu48 commented May 23, 2024

Thank you everyone!

containers/podman#22683 can be merged now as well, but it needs this dependency to be updated first. I guess renovate takes care of that?

@grisu48 grisu48 deleted the podmansh_sh branch May 23, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants