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

Add new setup_envs method for the Executor trait #2820

Merged
merged 7 commits into from
Jun 27, 2024

Conversation

musaprg
Copy link
Contributor

@musaprg musaprg commented Jun 18, 2024

fixes #2815

This PR introduces a new setup_envs method for the Executor trait. It allows any implementors of the Executor trait to control how environment variables specified in the OCI spec are handled. The default implementation mirrors the behavior of the one implemented in the container_init_process, which involves removing existing environment variables and setting the ones specified in the OCI spec.

TODO

  • Make consensus about the interface
  • Consider defining a dedicated error instead of ExecutorError
  • Add missing test cases

Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
@jprendes jprendes added enhancement New feature or request kind/feature labels Jun 18, 2024
@utam0k
Copy link
Member

utam0k commented Jun 19, 2024

cc: @Mossaka

Copy link
Contributor

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks @musaprg for working on this!
Now we just needs to get a green CI run :-)

crates/libcontainer/src/workload/mod.rs Outdated Show resolved Hide resolved
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
@musaprg musaprg marked this pull request as ready for review June 20, 2024 17:25
@musaprg musaprg requested a review from jprendes June 20, 2024 17:26
Copy link
Contributor

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

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

LGMT, one question to clarify

crates/libcontainer/src/process/container_init_process.rs Outdated Show resolved Hide resolved
@utam0k utam0k requested a review from a team June 21, 2024 11:07
crates/libcontainer/src/workload/default.rs Show resolved Hide resolved
Comment on lines 75 to 76
/// Set environment variables for the container process to be executed.
fn set_envs(&self, envs: HashMap<String, String>) -> Result<(), ExecutorSetEnvsError> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think set is a proper word for this method because we need to delete and add the envs. How about update or setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setup_envs sounds good to me. Let me rename the method and related type names.

Copy link
Contributor Author

@musaprg musaprg Jun 26, 2024

Choose a reason for hiding this comment

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

I've renamed in 9fbeef5

@@ -60,6 +71,16 @@ pub trait Executor: CloneBoxExecutor {
/// namespace and cgroups, and pivot_root into the rootfs. But this step
/// runs before waiting for the container start signal.
fn validate(&self, spec: &Spec) -> Result<(), ExecutorValidationError>;

/// Set environment variables for the container process to be executed.
Copy link
Member

Choose a reason for hiding this comment

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

It'd be better to explain the situation this method is called. For example, this method is called the init process and hasn't cleared the host's envs yet.

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've added a detailed description for the setup_envs in b20b8fa.

Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
@musaprg musaprg changed the title Add new set_envs method for the Executor trait Add new setup_envs method for the Executor trait Jun 26, 2024
@musaprg musaprg requested review from Mossaka and utam0k June 26, 2024 15:55
@musaprg
Copy link
Contributor Author

musaprg commented Jun 26, 2024

@Mossaka @utam0k @jprendes Hi. Thanks for the reviews! I've updated my PR based on your comments. Would you recheck again?

Copy link
Contributor

@Mossaka Mossaka 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

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

LGTM!

@yihuaf yihuaf merged commit bdd5aab into containers:main Jun 27, 2024
28 checks passed
@github-actions github-actions bot mentioned this pull request Jun 27, 2024
Copy link
Collaborator

@yihuaf yihuaf left a comment

Choose a reason for hiding this comment

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

LGTM

@musaprg musaprg deleted the issue-2815 branch June 27, 2024 14:25
@utam0k
Copy link
Member

utam0k commented Jun 28, 2024

@musaprg Congrats! 🎉 Thanks for your contribution.

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.

Options to pass env vars from OCI Spec to WASI Context
5 participants