Skip to content

Commit

Permalink
chore(bors): merge pull request #872
Browse files Browse the repository at this point in the history
872: feat(csi-node): allow listening on IPv6 Pod IPs r=michaelbeaumont a=michaelbeaumont

See openebs/mayastor#1731

Co-authored-by: Mike Beaumont <[email protected]>
  • Loading branch information
mayastor-bors and michaelbeaumont committed Oct 14, 2024
2 parents ddd9d36 + 27109e4 commit 3825922
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions control-plane/csi-driver/src/bin/node/main_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
env, fs,
future::Future,
io::ErrorKind,
net::SocketAddr,
net::{IpAddr, SocketAddr},
pin::Pin,
str::FromStr,
sync::Arc,
Expand Down Expand Up @@ -132,8 +132,26 @@ pub(super) async fn main() -> anyhow::Result<()> {
.short('g')
.long("grpc-endpoint")
.value_name("ENDPOINT")
.conflicts_with_all(["grpc-ip", "grpc-port"])
.help("ip address where this instance runs, and optionally the gRPC port")
.default_value("[::]")
.required(false)
)
.arg(
Arg::new("grpc-ip")
.long("grpc-ip")
.value_parser(clap::value_parser!(IpAddr))
.value_name("GRPC_IP")
.help("ip address this instance listens on")
.default_value("::")
.required(false)
)
.arg(
Arg::new("grpc-port")
.long("grpc-port")
.value_parser(clap::value_parser!(u16))
.value_name("GRPC_PORT")
.help("port this instance listens on")
.default_value(GRPC_PORT.to_string())
.required(false)
)
.arg(
Expand Down Expand Up @@ -330,10 +348,7 @@ pub(super) async fn main() -> anyhow::Result<()> {
let registration_enabled = matches.get_flag("enable-registration");

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

// Start the CSI server, node plugin grpc server and registration loop if registration is
// enabled.
Expand Down Expand Up @@ -427,21 +442,32 @@ async fn check_ana_and_label_node(

/// Validate that the grpc endpoint is valid.
fn validate_endpoints(
grpc_endpoint: &str,
matches: &clap::ArgMatches,
registration_enabled: bool,
) -> anyhow::Result<SocketAddr> {
let grpc_endpoint = if grpc_endpoint.contains(':') {
grpc_endpoint.to_string()
} else {
format!("{grpc_endpoint}:{GRPC_PORT}")
let grpc_endpoint = matches.get_one::<String>("grpc-endpoint");
let grpc_ip = matches.get_one::<IpAddr>("grpc-ip");
let grpc_port = matches.get_one::<u16>("grpc-port");
let grpc_endpoint_socket_addr = match grpc_endpoint {
None => SocketAddr::new(
*grpc_ip.expect("grpc-ip must be provided if grpc-endpoint is missing"),
*grpc_port.expect("grpc-port must be provided if grpc-endpoint is missing"),
),
Some(grpc_endpoint) => {
let grpc_endpoint = if grpc_endpoint.contains(':') {
grpc_endpoint.to_string()
} else {
format!("{grpc_endpoint}:{GRPC_PORT}")
};
SocketAddr::from_str(&grpc_endpoint)?
}
};
let grpc_endpoint_url = SocketAddr::from_str(&grpc_endpoint)?;
// Should not allow using an unspecified ip if registration is enabled as grpc endpoint gets
// sent in registration request.
if registration_enabled && grpc_endpoint_url.ip().is_unspecified() {
if registration_enabled && grpc_endpoint_socket_addr.ip().is_unspecified() {
return Err(anyhow::format_err!(
"gRPC endpoint: `[::]`/`0.0.0.0` is not allowed if registration is enabled"
));
}
Ok(grpc_endpoint_url)
Ok(grpc_endpoint_socket_addr)
}

0 comments on commit 3825922

Please sign in to comment.