Skip to content

Commit e073b58

Browse files
author
mayastor-bors
committed
Try #872:
2 parents 1406608 + 27109e4 commit e073b58

File tree

1 file changed

+40
-14
lines changed
  • control-plane/csi-driver/src/bin/node

1 file changed

+40
-14
lines changed

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

Lines changed: 40 additions & 14 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,
@@ -132,8 +132,26 @@ pub(super) async fn main() -> anyhow::Result<()> {
132132
.short('g')
133133
.long("grpc-endpoint")
134134
.value_name("ENDPOINT")
135+
.conflicts_with_all(["grpc-ip", "grpc-port"])
135136
.help("ip address where this instance runs, and optionally the gRPC port")
136-
.default_value("[::]")
137+
.required(false)
138+
)
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())
137155
.required(false)
138156
)
139157
.arg(
@@ -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,32 @@ 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()
435-
} else {
436-
format!("{grpc_endpoint}:{GRPC_PORT}")
448+
let grpc_endpoint = matches.get_one::<String>("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 = match grpc_endpoint {
452+
None => SocketAddr::new(
453+
*grpc_ip.expect("grpc-ip must be provided if grpc-endpoint is missing"),
454+
*grpc_port.expect("grpc-port must be provided if grpc-endpoint is missing"),
455+
),
456+
Some(grpc_endpoint) => {
457+
let grpc_endpoint = if grpc_endpoint.contains(':') {
458+
grpc_endpoint.to_string()
459+
} else {
460+
format!("{grpc_endpoint}:{GRPC_PORT}")
461+
};
462+
SocketAddr::from_str(&grpc_endpoint)?
463+
}
437464
};
438-
let grpc_endpoint_url = SocketAddr::from_str(&grpc_endpoint)?;
439465
// Should not allow using an unspecified ip if registration is enabled as grpc endpoint gets
440466
// sent in registration request.
441-
if registration_enabled && grpc_endpoint_url.ip().is_unspecified() {
467+
if registration_enabled && grpc_endpoint_socket_addr.ip().is_unspecified() {
442468
return Err(anyhow::format_err!(
443469
"gRPC endpoint: `[::]`/`0.0.0.0` is not allowed if registration is enabled"
444470
));
445471
}
446-
Ok(grpc_endpoint_url)
472+
Ok(grpc_endpoint_socket_addr)
447473
}

0 commit comments

Comments
 (0)