Skip to content

Commit

Permalink
Formatting fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Webster <[email protected]>
  • Loading branch information
esw-amzn committed Feb 21, 2025
1 parent 41c2313 commit 864af30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 2 additions & 4 deletions kube-client/src/api/remote_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ pub struct AttachedProcess {
}

impl AttachedProcess {
pub(crate) fn new(connection: Connection, ap: &AttachParams) -> Self
{
pub(crate) fn new(connection: Connection, ap: &AttachParams) -> Self {
// To simplify the implementation, always create a pipe for stdin.
// The caller does not have access to it unless they had requested.
let (stdin_writer, stdin_reader) = tokio::io::duplex(ap.max_stdin_buf_size.unwrap_or(MAX_BUF_SIZE));
Expand Down Expand Up @@ -274,8 +273,7 @@ async fn start_message_loop(
mut stderr: Option<impl AsyncWrite + Unpin>,
status_tx: StatusSender,
mut terminal_size_rx: Option<TerminalSizeReceiver>,
) -> Result<(), Error>
{
) -> Result<(), Error> {
let supports_stream_close = connection.supports_stream_close();
let stream = connection.into_stream();
let mut stdin_stream = tokio_util::io::ReaderStream::new(stdin);
Expand Down
17 changes: 8 additions & 9 deletions kube-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ impl Client {
/// Make WebSocket connection.
#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
pub async fn connect(
&self,
request: Request<Vec<u8>>,
) -> Result<Connection> {
pub async fn connect(&self, request: Request<Vec<u8>>) -> Result<Connection> {
use http::header::HeaderValue;
let (mut parts, body) = request.into_parts();
parts
Expand All @@ -241,11 +238,13 @@ impl Client {
match hyper::upgrade::on(res).await {
Ok(upgraded) => Ok(Connection {
stream: WebSocketStream::from_raw_socket(
TokioIo::new(upgraded),
ws::protocol::Role::Client,
None,
)
.await, protocol}),
TokioIo::new(upgraded),
ws::protocol::Role::Client,
None,
)
.await,
protocol,
}),

Err(e) => Err(Error::UpgradeConnection(
UpgradeConnectionError::GetPendingUpgrade(e),
Expand Down
33 changes: 18 additions & 15 deletions kube-client/src/client/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub enum StreamProtocol {
impl StreamProtocol {
pub fn as_str(&self) -> &'static str {
match self {
StreamProtocol::V4 => "v4.channel.k8s.io",
StreamProtocol::V5 => "v5.channel.k8s.io"
Self::V4 => "v4.channel.k8s.io",
Self::V5 => "v5.channel.k8s.io",
}
}

Expand All @@ -29,23 +29,23 @@ impl StreamProtocol {

pub fn supports_stream_close(&self) -> bool {
match self {
StreamProtocol::V4 => false,
StreamProtocol::V5 => true
Self::V4 => false,
Self::V5 => true,

Check warning on line 33 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L33

Added line #L33 was not covered by tests
}
}

/// Add HTTP header SEC_WEBSOCKET_PROTOCOL with a list of supported protocol.
pub fn add_to_headers(headers: &mut http::HeaderMap) -> Result<()> {
// Protocols we support in our preferred order.
let supported_protocols = vec![
let supported_protocols = [
// v5 supports CLOSE signals.
StreamProtocol::V5.as_str(),
Self::V5.as_str(),
// Use the binary subprotocol v4, to get JSON `Status` object in `error` channel (3).
// There's no official documentation about this protocol, but it's described in
// [`k8s.io/apiserver/pkg/util/wsstream/conn.go`](https://git.io/JLQED).
// There's a comment about v4 and `Status` object in
// [`kublet/cri/streaming/remotecommand/httpstream.go`](https://git.io/JLQEh).
StreamProtocol::V4.as_str(),
Self::V4.as_str(),
];

let header_value_string = supported_protocols.join(", ");
Expand All @@ -65,16 +65,19 @@ impl StreamProtocol {

match headers
.get(http::header::SEC_WEBSOCKET_PROTOCOL)

Check warning on line 67 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L67

Added line #L67 was not covered by tests
.map(|h| h.as_bytes()) {
Some(protocol) => if protocol == StreamProtocol::V4.as_bytes() {
Some(StreamProtocol::V4)
} else if protocol == StreamProtocol::V5.as_bytes() {
Some(StreamProtocol::V5)
.map(|h| h.as_bytes())
{
Some(protocol) => {
if protocol == Self::V4.as_bytes() {
Some(Self::V4)
} else if protocol == Self::V5.as_bytes() {
Some(Self::V5)

Check warning on line 74 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L73-L74

Added lines #L73 - L74 were not covered by tests
} else {
None

Check warning on line 76 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L76

Added line #L76 was not covered by tests
},
_ => None,
}
}
_ => None,

Check warning on line 79 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L79

Added line #L79 was not covered by tests
}
}
}

Expand Down Expand Up @@ -149,7 +152,7 @@ pub fn verify_response(res: &Response<Body>, key: &str) -> Result<StreamProtocol
// Make sure that the server returned an expected subprotocol.
let protocol = match StreamProtocol::get_from_response(res) {
Some(p) => p,
None => return Err(UpgradeConnectionError::SecWebSocketProtocolMismatch)
None => return Err(UpgradeConnectionError::SecWebSocketProtocolMismatch),

Check warning on line 155 in kube-client/src/client/upgrade.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/upgrade.rs#L155

Added line #L155 was not covered by tests
};

Ok(protocol)
Expand Down

0 comments on commit 864af30

Please sign in to comment.