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

feat(composer): allow setting 'host' network mode #96

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

dsharma-dc
Copy link
Contributor

@dsharma-dc dsharma-dc commented Oct 1, 2024

  • Allows to set network driver as 'host' in composer
  • Does not change anything in current behaviour as the current tests work without host network.
  • Has limitation at the moment that container will be returning grpc handle using loopback IP, hence creating more than one container on host network isn't safe.

Can be refined further as use case evolves.

@@ -694,6 +702,12 @@ impl Builder {
Ok(self)
}

/// set the network mode for this test.
pub fn network_mode(mut self, mode: &str) -> Result<Builder, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is mode? Suggest you use an enum for the public facing api

if self.network_mode.is_none() {
compose.network_id = compose.network_create().await.map_err(|e| e.to_string())?;
} else {
let host_nw = &compose.host_network().await?[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

what is [0] index here?

compose.network_id = compose.network_create().await.map_err(|e| e.to_string())?;
} else {
let host_nw = &compose.host_network().await?[0];
compose.network_id = host_nw.id.clone().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should return an error if no [0] and this unwrap

@@ -1282,7 +1319,7 @@ impl ComposeTest {
async fn create_container(
&self,
spec: &ContainerSpec,
ipv4: Ipv4Addr,
ipv4: Option<Ipv4Addr>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the ip optional, because it's not in control of docker so it's up to the host?
Can we not set 127.0.0.1 in case of host?

let mut env = self.spec_environment(spec);
env.push(format!("MY_POD_IP={ipv4}"));
let mut env = spec.environment();
env.push(format!("MY_POD_IP={:?}", ipv4.unwrap_or(Ipv4Addr::new(127, 0, 0, 1))));
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah so every container gets the same ip?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants