Skip to content

Commit

Permalink
handle cases where pod has ipv6 (#2791)
Browse files Browse the repository at this point in the history
* handle cases where pod has ipv6

* ..
  • Loading branch information
aviramha authored Sep 30, 2024
1 parent bddf4c3 commit 97e1387
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/2788.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle cases where pod has IPv6
9 changes: 8 additions & 1 deletion mirrord/kube/src/api/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ impl KubernetesAPI {
let pod_ips = runtime_data
.as_ref()
.filter(|runtime_data| !runtime_data.pod_ips.is_empty())
.map(|runtime_data| runtime_data.pod_ips.join(","));
.map(|runtime_data| {
runtime_data
.pod_ips
.iter()
.map(|ip| ip.to_string())
.collect::<Vec<_>>()
.join(",")
});

let params = ContainerParams::new(tls_cert, pod_ips);

Expand Down
12 changes: 10 additions & 2 deletions mirrord/kube/src/api/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
collections::BTreeMap,
convert::Infallible,
fmt::{self, Display, Formatter},
net::Ipv4Addr,
ops::FromResidual,
str::FromStr,
};
Expand Down Expand Up @@ -70,7 +71,7 @@ impl Display for ContainerRuntime {
#[derive(Debug)]
pub struct RuntimeData {
pub pod_name: String,
pub pod_ips: Vec<String>,
pub pod_ips: Vec<Ipv4Addr>,
pub pod_namespace: Option<String>,
pub node_name: String,
pub container_id: String,
Expand Down Expand Up @@ -125,7 +126,14 @@ impl RuntimeData {
.ok_or_else(|| KubeApiError::missing_field(pod, ".status.podIPs"))?
.iter()
.filter_map(|pod_ip| pod_ip.ip.as_ref())
.cloned()
.filter_map(|pod_ip| {
pod_ip
.parse::<Ipv4Addr>()
.inspect_err(|e| {
tracing::warn!("failed to parse pod IP {pod_ip}: {e:?}");
})
.ok()
})
.collect();

let container_statuses = pod
Expand Down

0 comments on commit 97e1387

Please sign in to comment.