From 3be2b1408b00aba31ab6a2b66d38737599d4b968 Mon Sep 17 00:00:00 2001 From: Mark Ingram Date: Tue, 5 Nov 2024 22:10:02 +0000 Subject: [PATCH] Feature: Add config setting to disable gzip compression #1627 - rounds out all of the https://kubernetes.io/docs/reference/config-api/kubeconfig.v1/#Cluster options Signed-off-by: Mark Ingram --- kube-client/src/client/builder.rs | 8 +++++++- kube-client/src/config/file_config.rs | 8 ++++++++ kube-client/src/config/mod.rs | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kube-client/src/client/builder.rs b/kube-client/src/client/builder.rs index 05edf80b4..1f9578ab3 100644 --- a/kube-client/src/client/builder.rs +++ b/kube-client/src/client/builder.rs @@ -158,7 +158,13 @@ where #[cfg(feature = "gzip")] let stack = ServiceBuilder::new() .layer(stack) - .layer(tower_http::decompression::DecompressionLayer::new()) + .layer( + tower_http::decompression::DecompressionLayer::new() + .no_br() + .no_deflate() + .no_zstd() + .gzip(!config.disable_compression), + ) .into_inner(); let service = ServiceBuilder::new() diff --git a/kube-client/src/config/file_config.rs b/kube-client/src/config/file_config.rs index 086f3753e..8a884174c 100644 --- a/kube-client/src/config/file_config.rs +++ b/kube-client/src/config/file_config.rs @@ -111,6 +111,14 @@ pub struct Cluster { #[serde(rename = "proxy-url")] #[serde(skip_serializing_if = "Option::is_none")] pub proxy_url: Option, + /// Compression is enabled by default with the `gzip` feature. + /// `disable_compression` allows client to opt-out of response compression for all requests to the server. + /// This is useful to speed up requests (specifically lists) when client-server network bandwidth is ample, + /// by saving time on compression (server-side) and decompression (client-side): + /// https://github.com/kubernetes/kubernetes/issues/112296 + #[serde(rename = "disable-compression")] + #[serde(skip_serializing_if = "Option::is_none")] + pub disable_compression: Option, /// Name used to check server certificate. /// /// If `tls_server_name` is `None`, the hostname used to contact the server is used. diff --git a/kube-client/src/config/mod.rs b/kube-client/src/config/mod.rs index 20f25d21a..e8f179dbf 100644 --- a/kube-client/src/config/mod.rs +++ b/kube-client/src/config/mod.rs @@ -151,6 +151,8 @@ pub struct Config { pub accept_invalid_certs: bool, /// Stores information to tell the cluster who you are. pub auth_info: AuthInfo, + /// Whether to disable compression (would only have an effect when the `gzip` feature is enabled) + pub disable_compression: bool, /// Optional proxy URL. Proxy support requires the `socks5` feature. pub proxy_url: Option, /// If set, apiserver certificate will be validated to contain this string @@ -177,6 +179,7 @@ impl Config { write_timeout: Some(DEFAULT_WRITE_TIMEOUT), accept_invalid_certs: false, auth_info: AuthInfo::default(), + disable_compression: false, proxy_url: None, tls_server_name: None, headers: Vec::new(), @@ -259,6 +262,7 @@ impl Config { token_file: Some(incluster_config::token_file()), ..Default::default() }, + disable_compression: false, proxy_url: None, tls_server_name: None, headers: Vec::new(), @@ -302,6 +306,8 @@ impl Config { .unwrap_or_else(|| String::from("default")); let accept_invalid_certs = loader.cluster.insecure_skip_tls_verify.unwrap_or(false); + let disable_compression = loader.cluster.disable_compression.unwrap_or(false); + let mut root_cert = None; if let Some(ca_bundle) = loader.ca_bundle()? { @@ -316,6 +322,7 @@ impl Config { read_timeout: Some(DEFAULT_READ_TIMEOUT), write_timeout: Some(DEFAULT_WRITE_TIMEOUT), accept_invalid_certs, + disable_compression, proxy_url: loader.proxy_url()?, auth_info: loader.user, tls_server_name: loader.cluster.tls_server_name,