Skip to content

Commit

Permalink
use valid format for dummy uris connect through UDS channel
Browse files Browse the repository at this point in the history
Signed-off-by: Johnson Shih <[email protected]>
  • Loading branch information
johnsonshih committed Oct 12, 2023
1 parent cc29959 commit a911e23
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion agent/src/util/device_plugin_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ impl DevicePluginBuilder {
};

// We will ignore this dummy uri because UDS does not use it.
// Some servers will check the uri content so the uri needs to
// be in valid format even it's not used, the scheme part is used
// to specific what scheme to use, such as http or https
let kubelet_socket_closure = kubelet_socket.to_string();
let channel = Endpoint::try_from("http://[::]:50051")?
let channel = Endpoint::try_from("http://[::1]:50051")?
.connect_with_connector(service_fn(move |_: Uri| {
UnixStream::connect(kubelet_socket_closure.clone())
}))
Expand Down
5 changes: 4 additions & 1 deletion agent/src/util/discovery_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ impl DiscoveryOperator {
// Clone socket for closure which has static lifetime
let socket = socket.clone();
// We will ignore this dummy uri because UDS does not use it.
match Endpoint::try_from("http://[::]:50051")
// Some servers will check the uri content so the uri needs to
// be in valid format even it's not used, the scheme part is used
// to specific what scheme to use, such as http or https
match Endpoint::try_from("http://[::1]:50051")
.unwrap()
.connect_with_connector(tower::service_fn(move |_: Uri| {
let endpoint = socket.clone();
Expand Down
2 changes: 1 addition & 1 deletion agent/src/util/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod tests {
.await
.is_ok());
// Connect to registration service
let channel = Endpoint::try_from("http://[::]:50051")
let channel = Endpoint::try_from("http://[::1]:50051")
.unwrap()
.connect_with_connector(tower::service_fn(move |_: Uri| {
UnixStream::connect(registration_socket_path_string.clone())
Expand Down
2 changes: 1 addition & 1 deletion discovery-utils/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub mod server {
Vec::new(),
)
.await;
let channel = Endpoint::try_from("http://[::]:50051")
let channel = Endpoint::try_from("http://[::1]:50051")
.unwrap()
.connect_with_connector(tower::service_fn(move |_: Uri| {
UnixStream::connect(discovery_handler_socket.clone())
Expand Down
5 changes: 4 additions & 1 deletion discovery-utils/src/registration_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ pub async fn register_discovery_handler(
info!("register_discovery_handler - entered");
loop {
// We will ignore this dummy uri because UDS does not use it.
if let Ok(channel) = Endpoint::try_from("http://[::]:50051")?
// Some servers will check the uri content so the uri needs to
// be in valid format even it's not used, the scheme part is used
// to specific what scheme to use, such as http or https
if let Ok(channel) = Endpoint::try_from("http://[::1]:50051")?
.connect_with_connector(tower::service_fn(move |_: Uri| {
tokio::net::UnixStream::connect(super::get_registration_socket())
}))
Expand Down
5 changes: 4 additions & 1 deletion shared/src/uds/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ pub async fn try_connect(socket_path: &str) -> Result<(), anyhow::Error> {
{
let path = socket_path.to_string();
// We will ignore this dummy uri because UDS does not use it.
if let Ok(_v) = tonic::transport::Endpoint::try_from("http://[::]:50051")
// Some servers will check the uri content so the uri needs to
// be in valid format even it's not used, the scheme part is used
// to specific what scheme to use, such as http or https
if let Ok(_v) = tonic::transport::Endpoint::try_from("http://[::1]:50051")
.map_err(|e| anyhow::format_err!("{}", e))?
.connect_with_connector(tower::service_fn(move |_: tonic::transport::Uri| {
tokio::net::UnixStream::connect(path.clone())
Expand Down

0 comments on commit a911e23

Please sign in to comment.