Skip to content

Commit

Permalink
Merge branch 'support-untagged-enums' of github.com:sbernauer/kube in…
Browse files Browse the repository at this point in the history
…to support-untagged-enums
  • Loading branch information
sbernauer committed Oct 7, 2022
2 parents fd219e1 + 5d7bf1d commit c7ab486
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 45 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
@@ -1 +1 @@
blacklisted-names = []
disallowed-names = []
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Expand Up @@ -50,7 +50,7 @@ tower-http = { version = "0.3.2", features = ["trace", "decompression-gzip"] }
hyper = { version = "0.14.13", features = ["client", "http1", "stream", "tcp"] }
thiserror = "1.0.29"
backoff = "0.4.0"
clap = { version = "3.1.9", default-features = false, features = ["std", "cargo", "derive"] }
clap = { version = "4.0", default-features = false, features = ["std", "cargo", "derive"] }
edit = "0.1.3"
tokio-stream = { version = "0.1.9", features = ["net"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive.rs
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
/// Our spec for Foo
///
/// A struct with our chosen Kind will be created for us, using the following kube attrs
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Clone, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, JsonSchema)]
#[kube(
group = "clux.dev",
version = "v1",
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive_schema.rs
Expand Up @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize};
// - https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting
// - https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting-and-nullable

#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Clone, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, JsonSchema)]
#[kube(
group = "clux.dev",
version = "v1",
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_client_trace.rs
Expand Up @@ -42,9 +42,9 @@ async fn main() -> anyhow::Result<()> {
})
.on_response(|response: &Response<Body>, latency: Duration, span: &Span| {
let status = response.status();
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
if status.is_client_error() || status.is_server_error() {
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
}
tracing::debug!("finished in {}ms", latency.as_millis())
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic_jsonpath.rs
Expand Up @@ -20,12 +20,12 @@ async fn main() -> anyhow::Result<()> {
);

let pods: Api<Pod> = Api::<Pod>::all(client);
let list_params = ListParams::default().fields(&*field_selector);
let list_params = ListParams::default().fields(&field_selector);
let list = pods.list(&list_params).await?;

// Use the given JSONPATH to filter the ObjectList
let list_json = serde_json::to_value(&list)?;
let res = jsonpath_lib::select(&list_json, &*jsonpath).unwrap();
let res = jsonpath_lib::select(&list_json, &jsonpath).unwrap();
info!("\t\t {:?}", res);
Ok(())
}
34 changes: 22 additions & 12 deletions examples/kubectl.rs
Expand Up @@ -21,33 +21,43 @@ use tracing::*;

#[derive(clap::Parser)]
struct App {
#[clap(long, short, arg_enum, default_value_t)]
#[arg(long, short, default_value_t = OutputMode::Pretty)]
output: OutputMode,
#[clap(long, short)]
#[arg(long, short)]
file: Option<std::path::PathBuf>,
#[clap(long, short = 'l')]
#[arg(long, short = 'l')]
selector: Option<String>,
#[clap(long, short)]
#[arg(long, short)]
namespace: Option<String>,
#[clap(long, short = 'A')]
#[arg(long, short = 'A')]
all: bool,
#[clap(arg_enum)]
verb: Verb,
resource: Option<String>,
name: Option<String>,
}

#[derive(clap::ArgEnum, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq, clap::ValueEnum)]
enum OutputMode {
Pretty,
Yaml,
}
impl Default for OutputMode {
fn default() -> Self {
Self::Pretty

impl OutputMode {
fn as_str(&self) -> &'static str {
match self {
Self::Pretty => "pretty",
Self::Yaml => "yaml",
}
}
}

impl std::fmt::Display for OutputMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.pad(self.as_str())
}
}
#[derive(clap::ArgEnum, Clone, PartialEq, Eq, Debug)]

#[derive(Clone, PartialEq, Eq, Debug, clap::ValueEnum)]
enum Verb {
Get,
Delete,
Expand All @@ -64,7 +74,7 @@ fn resolve_api_resource(discovery: &Discovery, name: &str) -> Option<(ApiResourc
.groups()
.flat_map(|group| {
group
.recommended_resources()
.resources_by_stability()
.into_iter()
.map(move |res| (group, res))
})
Expand Down
2 changes: 1 addition & 1 deletion examples/pod_cp.rs
Expand Up @@ -58,7 +58,7 @@ async fn main() -> anyhow::Result<()> {
// Write the data to pod
{
let mut header = tar::Header::new_gnu();
header.set_path(&file_name).unwrap();
header.set_path(file_name).unwrap();
header.set_size(data.len() as u64);
header.set_cksum();

Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/api/mod.rs
Expand Up @@ -254,6 +254,6 @@ mod test {
let _: Api<corev1::Node> = Api::all(client.clone());
let _: Api<corev1::Pod> = Api::default_namespaced(client.clone());
let _: Api<corev1::PersistentVolume> = Api::all(client.clone());
let _: Api<corev1::ConfigMap> = Api::namespaced(client.clone(), "default");
let _: Api<corev1::ConfigMap> = Api::namespaced(client, "default");
}
}
8 changes: 4 additions & 4 deletions kube-client/src/client/builder.rs
Expand Up @@ -143,9 +143,9 @@ impl TryFrom<Config> for ClientBuilder<BoxService<Request<hyper::Body>, Response
})
.on_response(|res: &Response<hyper::Body>, _latency: Duration, span: &Span| {
let status = res.status();
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
if status.is_client_error() || status.is_server_error() {
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
}
})
// Explicitly disable `on_body_chunk`. The default does nothing.
Expand All @@ -159,10 +159,10 @@ impl TryFrom<Config> for ClientBuilder<BoxService<Request<hyper::Body>, Response
// - Polling `Body` errored
// - the response was classified as failure (5xx)
// - End of stream was classified as failure
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
match ec {
ServerErrorsFailureClass::StatusCode(status) => {
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
tracing::error!("failed with status {}", status)
}
ServerErrorsFailureClass::Error(err) => {
Expand Down
22 changes: 21 additions & 1 deletion kube-client/src/client/tls.rs
Expand Up @@ -83,7 +83,8 @@ pub mod rustls_tls {
use hyper_rustls::ConfigBuilderExt;
use rustls::{
self,
client::{ServerCertVerified, ServerCertVerifier},
client::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
internal::msgs::handshake::DigitallySignedStruct,
Certificate, ClientConfig, PrivateKey,
};
use thiserror::Error;
Expand Down Expand Up @@ -194,8 +195,27 @@ pub mod rustls_tls {
_ocsp_response: &[u8],
_now: std::time::SystemTime,
) -> Result<ServerCertVerified, rustls::Error> {
tracing::warn!("Server cert bypassed");
Ok(ServerCertVerified::assertion())
}

fn verify_tls13_signature(
&self,
_message: &[u8],
_cert: &Certificate,
_dss: &DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, rustls::Error> {
Ok(HandshakeSignatureValid::assertion())
}

fn verify_tls12_signature(
&self,
_message: &[u8],
_cert: &Certificate,
_dss: &DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, rustls::Error> {
Ok(HandshakeSignatureValid::assertion())
}
}
}

Expand Down
18 changes: 9 additions & 9 deletions kube-client/src/config/file_config.rs
Expand Up @@ -51,7 +51,7 @@ pub struct Kubeconfig {

/// Preferences stores extensions for cli.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Preferences {
/// Enable colors
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -63,7 +63,7 @@ pub struct Preferences {

/// NamedExtention associates name with extension.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedExtension {
/// Name of extension
pub name: String,
Expand All @@ -73,7 +73,7 @@ pub struct NamedExtension {

/// NamedCluster associates name with cluster.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedCluster {
/// Name of cluster
pub name: String,
Expand All @@ -83,7 +83,7 @@ pub struct NamedCluster {

/// Cluster stores information to connect Kubernetes cluster.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Cluster {
/// The address of the kubernetes cluster (https://hostname:port).
pub server: String,
Expand Down Expand Up @@ -209,13 +209,13 @@ pub struct AuthInfo {
#[cfg(test)]
impl PartialEq for AuthInfo {
fn eq(&self, other: &Self) -> bool {
serde_json::to_value(&self).unwrap() == serde_json::to_value(&other).unwrap()
serde_json::to_value(self).unwrap() == serde_json::to_value(other).unwrap()
}
}

/// AuthProviderConfig stores auth for specified cloud provider.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct AuthProviderConfig {
/// Name of the auth provider
pub name: String,
Expand All @@ -225,7 +225,7 @@ pub struct AuthProviderConfig {

/// ExecConfig stores credential-plugin configuration.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct ExecConfig {
/// Preferred input version of the ExecInfo.
///
Expand All @@ -247,7 +247,7 @@ pub struct ExecConfig {

/// NamedContext associates name with context.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedContext {
/// Name of the context
pub name: String,
Expand All @@ -257,7 +257,7 @@ pub struct NamedContext {

/// Context stores tuple of cluster and user information.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Context {
/// Name of the cluster for this context
pub cluster: String,
Expand Down

0 comments on commit c7ab486

Please sign in to comment.