Skip to content

Commit 5f5e2a9

Browse files
feat(csi-node): allow listening on IPv6 Pod IPs
1 parent 1406608 commit 5f5e2a9

File tree

1 file changed

+41
-12
lines changed
  • control-plane/csi-driver/src/bin/node

1 file changed

+41
-12
lines changed

control-plane/csi-driver/src/bin/node/main_.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::{
2929
env, fs,
3030
future::Future,
3131
io::ErrorKind,
32-
net::SocketAddr,
32+
net::{IpAddr, SocketAddr},
3333
pin::Pin,
3434
str::FromStr,
3535
sync::Arc,
@@ -136,6 +136,24 @@ pub(super) async fn main() -> anyhow::Result<()> {
136136
.default_value("[::]")
137137
.required(false)
138138
)
139+
.arg(
140+
Arg::new("grpc-ip")
141+
.long("grpc-ip")
142+
.value_parser(clap::value_parser!(IpAddr))
143+
.value_name("GRPC_IP")
144+
.help("ip address this instance listens on")
145+
.default_value("::")
146+
.required(false)
147+
)
148+
.arg(
149+
Arg::new("grpc-port")
150+
.long("grpc-port")
151+
.value_parser(clap::value_parser!(u16))
152+
.value_name("GRPC_PORT")
153+
.help("port this instance listens on")
154+
.default_value(GRPC_PORT.to_string())
155+
.required(false)
156+
)
139157
.arg(
140158
Arg::new("v")
141159
.short('v')
@@ -330,10 +348,7 @@ pub(super) async fn main() -> anyhow::Result<()> {
330348
let registration_enabled = matches.get_flag("enable-registration");
331349

332350
// Parse instance and grpc endpoints from the command line arguments and validate.
333-
let grpc_sock_addr = validate_endpoints(
334-
matches.get_one::<String>("grpc-endpoint").unwrap(),
335-
registration_enabled,
336-
)?;
351+
let grpc_sock_addr = validate_endpoints(&matches, registration_enabled)?;
337352

338353
// Start the CSI server, node plugin grpc server and registration loop if registration is
339354
// enabled.
@@ -427,21 +442,35 @@ async fn check_ana_and_label_node(
427442

428443
/// Validate that the grpc endpoint is valid.
429444
fn validate_endpoints(
430-
grpc_endpoint: &str,
445+
matches: &clap::ArgMatches,
431446
registration_enabled: bool,
432447
) -> anyhow::Result<SocketAddr> {
433-
let grpc_endpoint = if grpc_endpoint.contains(':') {
434-
grpc_endpoint.to_string()
448+
let grpc_endpoint_src = matches.value_source("grpc-endpoint");
449+
let grpc_ip = matches.get_one::<IpAddr>("grpc-ip");
450+
let grpc_port = matches.get_one::<u16>("grpc-port");
451+
let grpc_endpoint_socket_addr = if grpc_endpoint_src
452+
.unwrap_or(clap::parser::ValueSource::DefaultValue)
453+
== clap::parser::ValueSource::DefaultValue
454+
{
455+
SocketAddr::new(
456+
*grpc_ip.expect("must be provided if grpc-endpoint is missing"),
457+
*grpc_port.expect("must be provided if grpc-port is missing"),
458+
)
435459
} else {
436-
format!("{grpc_endpoint}:{GRPC_PORT}")
460+
let grpc_endpoint_arg = matches.get_one::<String>("grpc-endpoint").unwrap();
461+
let grpc_endpoint = if grpc_endpoint_arg.contains(':') {
462+
grpc_endpoint_arg.to_string()
463+
} else {
464+
format!("{grpc_endpoint_arg}:{GRPC_PORT}")
465+
};
466+
SocketAddr::from_str(&grpc_endpoint)?
437467
};
438-
let grpc_endpoint_url = SocketAddr::from_str(&grpc_endpoint)?;
439468
// Should not allow using an unspecified ip if registration is enabled as grpc endpoint gets
440469
// sent in registration request.
441-
if registration_enabled && grpc_endpoint_url.ip().is_unspecified() {
470+
if registration_enabled && grpc_endpoint_socket_addr.ip().is_unspecified() {
442471
return Err(anyhow::format_err!(
443472
"gRPC endpoint: `[::]`/`0.0.0.0` is not allowed if registration is enabled"
444473
));
445474
}
446-
Ok(grpc_endpoint_url)
475+
Ok(grpc_endpoint_socket_addr)
447476
}

0 commit comments

Comments
 (0)