Skip to content

Commit

Permalink
Merge pull request containers#1499 from mgjm-fork/create-container-en…
Browse files Browse the repository at this point in the history
…v-vars

Create container with environment variables
  • Loading branch information
openshift-merge-robot authored Jul 18, 2023
2 parents 9be4262 + 97d6b46 commit 271dee6
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 199 deletions.
2 changes: 2 additions & 0 deletions conmon-rs/common/proto/conmon.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface Conmon {
commandArgs @9 :List(Text);
metadataOld @10 :Data; # deprecated
metadata @11 :Metadata; # Standard metadata to carry.
envVars @12 :TextTextMap;
}

struct LogDriver {
Expand Down Expand Up @@ -72,6 +73,7 @@ interface Conmon {
terminal @3 :Bool;
metadataOld @4 :Data; # deprecated
metadata @5 :Metadata; # Standard metadata to carry.
envVars @6 :TextTextMap;
}

struct ExecSyncContainerResponse {
Expand Down
2 changes: 2 additions & 0 deletions conmon-rs/server/src/child_reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl ChildReaper {
stdin: bool,
container_io: &mut ContainerIO,
pidfile: &Path,
env_vars: Vec<(String, String)>,
) -> Result<(u32, CancellationToken)>
where
P: AsRef<OsStr>,
Expand All @@ -79,6 +80,7 @@ impl ChildReaper {
.args(args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.envs(env_vars)
.spawn()
.context("spawn child process: {}")?;

Expand Down
14 changes: 12 additions & 2 deletions conmon-rs/server/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
capnp_util,
child::Child,
container_io::{ContainerIO, SharedContainerIO},
container_log::ContainerLog,
Expand Down Expand Up @@ -134,13 +135,14 @@ impl conmon::Server for Server {
let runtime = self.config().runtime().clone();
let exit_paths = capnp_vec_path!(req.get_exit_paths());
let oom_exit_paths = capnp_vec_path!(req.get_oom_exit_paths());
let env_vars = pry!(req.get_env_vars().and_then(capnp_util::into_map));

Promise::from_future(
async move {
capnp_err!(container_log.write().await.init().await)?;

let (grandchild_pid, token) = capnp_err!(match child_reaper
.create_child(runtime, args, stdin, &mut container_io, &pidfile)
.create_child(runtime, args, stdin, &mut container_io, &pidfile, env_vars)
.await
{
Err(e) => {
Expand Down Expand Up @@ -212,11 +214,19 @@ impl conmon::Server for Server {

let command = pry!(req.get_command());
let args = pry_err!(self.generate_exec_sync_args(&id, &pidfile, &container_io, &command));
let env_vars = pry!(req.get_env_vars().and_then(capnp_util::into_map));

Promise::from_future(
async move {
match child_reaper
.create_child(&runtime, &args, false, &mut container_io, &pidfile)
.create_child(
&runtime,
&args,
false,
&mut container_io,
&pidfile,
env_vars,
)
.await
{
Ok((grandchild_pid, token)) => {
Expand Down
Loading

0 comments on commit 271dee6

Please sign in to comment.