@@ -29,7 +29,7 @@ use std::{
29
29
env, fs,
30
30
future:: Future ,
31
31
io:: ErrorKind ,
32
- net:: SocketAddr ,
32
+ net:: { IpAddr , SocketAddr } ,
33
33
pin:: Pin ,
34
34
str:: FromStr ,
35
35
sync:: Arc ,
@@ -136,6 +136,24 @@ pub(super) async fn main() -> anyhow::Result<()> {
136
136
. default_value ( "[::]" )
137
137
. required ( false )
138
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 ( ) )
155
+ . required ( false )
156
+ )
139
157
. arg (
140
158
Arg :: new ( "v" )
141
159
. short ( 'v' )
@@ -330,10 +348,7 @@ pub(super) async fn main() -> anyhow::Result<()> {
330
348
let registration_enabled = matches. get_flag ( "enable-registration" ) ;
331
349
332
350
// 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) ?;
337
352
338
353
// Start the CSI server, node plugin grpc server and registration loop if registration is
339
354
// enabled.
@@ -427,21 +442,35 @@ async fn check_ana_and_label_node(
427
442
428
443
/// Validate that the grpc endpoint is valid.
429
444
fn validate_endpoints (
430
- grpc_endpoint : & str ,
445
+ matches : & clap :: ArgMatches ,
431
446
registration_enabled : bool ,
432
447
) -> 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
+ )
435
459
} 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) ?
437
467
} ;
438
- let grpc_endpoint_url = SocketAddr :: from_str ( & grpc_endpoint) ?;
439
468
// Should not allow using an unspecified ip if registration is enabled as grpc endpoint gets
440
469
// 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 ( ) {
442
471
return Err ( anyhow:: format_err!(
443
472
"gRPC endpoint: `[::]`/`0.0.0.0` is not allowed if registration is enabled"
444
473
) ) ;
445
474
}
446
- Ok ( grpc_endpoint_url )
475
+ Ok ( grpc_endpoint_socket_addr )
447
476
}
0 commit comments