[go: nahoru, domu]

Skip to content

Commit

Permalink
chore(*): Fixes a whole host of clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Thomas <taylor@oftaylor.com>
  • Loading branch information
thomastaylor312 committed Oct 8, 2021
1 parent 2275956 commit 26ceb48
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions crates/kubelet/src/container/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ pub async fn patch_container_status(
key: &ContainerKey,
status: &Status,
) -> anyhow::Result<()> {
match pod.find_container(&key) {
match pod.find_container(key) {
Some(container) => {
let kube_status = status.to_kubernetes(container.name());

let patches = match pod.container_status_index(&key) {
let patches = match pod.container_status_index(key) {
Some(idx) => {
let path_prefix = if key.is_init() {
format!("/status/initContainerStatuses/{}", idx)
Expand Down
8 changes: 4 additions & 4 deletions crates/kubelet/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub async fn create<P: Provider>(client: &kube::Client, config: &Config, provide
"true",
);

node_labels_definition(P::ARCH, &config, &mut builder);
node_labels_definition(P::ARCH, config, &mut builder);

// TODO Do we want to detect this?
builder.add_capacity("cpu", "4");
Expand Down Expand Up @@ -137,7 +137,7 @@ pub async fn create<P: Provider>(client: &kube::Client, config: &Config, provide
match retry!(node_client.create(&PostParams::default(), &node).await, times: 4) {
Ok(node) => {
let node_uid = node.metadata.uid.unwrap();
if let Err(e) = create_lease(&node_uid, &config.node_name, &client).await {
if let Err(e) = create_lease(&node_uid, &config.node_name, client).await {
error!(error = %e, "Failed to create lease");
return;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ pub async fn evict_pods(client: &kube::Client, node_name: &str) -> anyhow::Resul
}
);
api.patch_status(
&pod.name(),
pod.name(),
&PatchParams::default(),
&kube::api::Patch::Strategic(patch),
)
Expand All @@ -234,7 +234,7 @@ pub async fn evict_pods(client: &kube::Client, node_name: &str) -> anyhow::Resul
info!("Marked static pod as terminated");
continue;
} else {
match evict_pod(&client, pod.name(), pod.namespace(), &mut stream).await {
match evict_pod(client, pod.name(), pod.namespace(), &mut stream).await {
Ok(_) => (),
Err(e) => {
// Absorb the error and attempt to delete other pods with best effort.
Expand Down
6 changes: 3 additions & 3 deletions crates/kubelet/src/pod/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn patch_status(api: &Api<KubePod>, name: &str, status: Status) {
debug!(?patch, "Applying status patch to pod");
match api
.patch_status(
&name,
name,
&PatchParams::default(),
&kube::api::Patch::Strategic(patch),
)
Expand Down Expand Up @@ -56,12 +56,12 @@ pub async fn initialize_pod_container_statuses(
Phase::Failed,
"Timed out while initializing container statuses.",
);
patch_status(&api, &name, status).await;
patch_status(api, &name, status).await;
anyhow::bail!("Timed out while initializing container statuses.")
}
let (num_containers, num_init_containers) = {
let pod = pod.latest();
patch_status(&api, &name, make_registered_status(&pod)).await;
patch_status(api, &name, make_registered_status(&pod)).await;
let num_containers = pod.containers().len();
let num_init_containers = pod.init_containers().len();
(num_containers, num_init_containers)
Expand Down
2 changes: 1 addition & 1 deletion crates/kubelet/src/state/common/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<P: GenericProvider> State<P::PodState> for Resources<P> {
}
// Do allocate for this Pod
if let Err(e) = device_plugin_manager
.do_allocate(&pod.pod_uid(), container_devices)
.do_allocate(pod.pod_uid(), container_devices)
.await
{
error!(error = %e);
Expand Down
2 changes: 1 addition & 1 deletion crates/kubelet/src/volume/persistentvolumeclaim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ async fn get_csi(
)))?;

let pv_client: Api<PersistentVolume> = Api::all(client.clone());
let pv = pv_client.get(&volume_name).await?;
let pv = pv_client.get(volume_name).await?;

// https://github.com/kubernetes/kubernetes/blob/734889ed822d1a60c6dd61ccd8f1ed0e8ab31ea5/pkg/volume/csi/csi_attacher.go#L295-L298
let csi = pv
Expand Down
52 changes: 26 additions & 26 deletions crates/oci-distribution/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Client {
) -> anyhow::Result<ImageData> {
debug!("Pulling image: {:?}", image);
let op = RegistryOperation::Pull;
if !self.tokens.contains_key(&image, op) {
if !self.tokens.contains_key(image, op) {
self.auth(image, auth, op).await?;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ impl Client {
) -> anyhow::Result<String> {
debug!("Pushing image: {:?}", image_ref);
let op = RegistryOperation::Push;
if !self.tokens.contains_key(&image_ref, op) {
if !self.tokens.contains_key(image_ref, op) {
self.auth(image_ref, auth, op).await?;
}

Expand Down Expand Up @@ -305,7 +305,7 @@ impl Client {
// Fall back to HTTP Basic Auth
if let RegistryAuth::Basic(username, password) = authentication {
self.tokens.insert(
&image,
image,
operation,
RegistryTokenType::Basic(username.to_string(), password.to_string()),
);
Expand Down Expand Up @@ -349,7 +349,7 @@ impl Client {
.context("Failed to decode registry token from auth request")?;
debug!("Succesfully authorized for image '{:?}'", image);
self.tokens
.insert(&image, operation, RegistryTokenType::Bearer(token));
.insert(image, operation, RegistryTokenType::Bearer(token));
Ok(())
}
_ => {
Expand All @@ -374,7 +374,7 @@ impl Client {
auth: &RegistryAuth,
) -> anyhow::Result<String> {
let op = RegistryOperation::Pull;
if !self.tokens.contains_key(&image, op) {
if !self.tokens.contains_key(image, op) {
self.auth(image, auth, op).await?;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ impl Client {
auth: &RegistryAuth,
) -> anyhow::Result<(OciManifest, String)> {
let op = RegistryOperation::Pull;
if !self.tokens.contains_key(&image, op) {
if !self.tokens.contains_key(image, op) {
self.auth(image, auth, op).await?;
}

Expand Down Expand Up @@ -570,7 +570,7 @@ impl Client {
auth: &RegistryAuth,
) -> anyhow::Result<(OciManifest, String, String)> {
let op = RegistryOperation::Pull;
if !self.tokens.contains_key(&image, op) {
if !self.tokens.contains_key(image, op) {
self.auth(image, auth, op).await?;
}

Expand Down Expand Up @@ -863,7 +863,7 @@ impl Client {
/// Convert a Reference to a v2 blob upload URL.
fn to_v2_blob_upload_url(&self, reference: &Reference) -> String {
self.to_v2_blob_url(
&reference.resolve_registry(),
reference.resolve_registry(),
reference.repository(),
"uploads/",
)
Expand Down Expand Up @@ -928,7 +928,7 @@ impl<'a> RequestBuilderWrapper<'a> {
) -> anyhow::Result<RequestBuilderWrapper> {
let mut headers = HeaderMap::new();

if let Some(token) = self.client.tokens.get(&image, op) {
if let Some(token) = self.client.tokens.get(image, op) {
match token {
RegistryTokenType::Bearer(token) => {
debug!("Using bearer token authentication.");
Expand Down Expand Up @@ -1267,7 +1267,7 @@ mod test {
assert_eq!(
"http://webassembly.azurecr.io/v2/hello/blobs/sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
c.to_v2_blob_url(
&reference.registry(),
reference.registry(),
reference.repository(),
reference.digest().unwrap()
)
Expand Down Expand Up @@ -1319,7 +1319,7 @@ mod test {
assert_eq!(
"https://webassembly.azurecr.io/v2/hello/blobs/sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
c.to_v2_blob_url(
&reference.registry(),
reference.registry(),
reference.repository(),
reference.digest().unwrap()
)
Expand All @@ -1339,7 +1339,7 @@ mod test {
assert_eq!(
"http://oci.registry.local/v2/hello/blobs/sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
c.to_v2_blob_url(
&reference.registry(),
reference.registry(),
reference.repository(),
reference.digest().unwrap()
)
Expand Down Expand Up @@ -1369,87 +1369,87 @@ mod test {
fn test_registry_token_deserialize() {
// 'token' field, standalone
let text = r#"{"token": "abc"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "abc");

// 'access_token' field, standalone
let text = r#"{"access_token": "xyz"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "xyz");

// both 'token' and 'access_token' fields, 'token' field takes precedence
let text = r#"{"access_token": "xyz", "token": "abc"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "abc");

// both 'token' and 'access_token' fields, 'token' field takes precedence (reverse order)
let text = r#"{"token": "abc", "access_token": "xyz"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "abc");

// non-string fields do not break parsing
let text = r#"{"aaa": 300, "access_token": "xyz", "token": "abc", "zzz": 600}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());

// Note: tokens should always be strings. The next two tests ensure that if one field
// is invalid (integer), then parse can still succeed if the other field is a string.
//
// numeric 'access_token' field, but string 'token' field does not in parse error
let text = r#"{"access_token": 300, "token": "abc"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "abc");

// numeric 'token' field, but string 'accesss_token' field does not in parse error
let text = r#"{"access_token": "xyz", "token": 300}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_ok());
let rt = res.unwrap();
assert_eq!(rt.token(), "xyz");

// numeric 'token' field results in parse error
let text = r#"{"token": 300}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// numeric 'access_token' field results in parse error
let text = r#"{"access_token": 300}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// object 'token' field results in parse error
let text = r#"{"token": {"some": "thing"}}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// object 'access_token' field results in parse error
let text = r#"{"access_token": {"some": "thing"}}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// missing fields results in parse error
let text = r#"{"some": "thing"}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// bad JSON results in parse error
let text = r#"{"token": "abc""#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());

// worse JSON results in parse error
let text = r#"_ _ _ kjbwef??98{9898 }} }}"#;
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(&text);
let res: Result<RegistryToken, serde_json::Error> = serde_json::from_str(text);
assert!(res.is_err());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/oci-distribution/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl Reference {
pub fn resolve_registry(&self) -> &str {
let registry = self.registry();
match registry {
"docker.io" => "registry-1.docker.io".into(),
_ => registry.into(),
"docker.io" => "registry-1.docker.io",
_ => registry,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oci-distribution/src/token_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TokenCache {
.claims()
.registered
.expiration
.unwrap_or_else(|| u64::MAX)
.unwrap_or(u64::MAX)
},
Err(error) => {
warn!(?error, "Invalid bearer token");
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Provider for WasiProvider {

// Evict all pods upon shutdown
async fn shutdown(&self, node_name: &str) -> anyhow::Result<()> {
node::drain(&self.shared.client, &node_name).await?;
node::drain(&self.shared.client, node_name).await?;
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-provider/src/states/container/waiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl State<ContainerState> for Waiting {

let mut env = kubelet::provider::env_vars(&container, &state.pod, &client).await;
env.extend(container_envs);
let args: Vec<String> = container.args().map(|t| t.clone()).unwrap_or_default();
let args: Vec<String> = container.args().map(|t| t.to_owned()).unwrap_or_default();

// TODO: ~magic~ number
let (tx, rx) = mpsc::channel(8);
Expand All @@ -175,7 +175,7 @@ impl State<ContainerState> for Waiting {

// Parse allowed domains from annotation key
if let Some(annotation) = annotations.get(ALLOWED_DOMAINS_ANNOTATION_KEY) {
match serde_json::from_str(&annotation) {
match serde_json::from_str(annotation) {
Ok(allowed_domains) => {
wasi_http_config.allowed_domains = Some(allowed_domains);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ContainerStatusExpectation<'_> {
"Expected {} to have state but it didn't",
container_name
)),
Some(state) => Self::verify_terminated_state(&state, container_name, expected),
Some(state) => Self::verify_terminated_state(state, container_name, expected),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions tests/podsmiter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ impl Smiter {
<T as kube::Resource>::DynamicType: Default,
{
let api: Api<T> = match self.namespace.as_ref() {
Some(ns) => Api::namespaced(client, &ns),
Some(ns) => Api::namespaced(client, ns),
None => Api::all(client),
};
let smite_operations = self
.names_to_smite
.iter()
.map(|name| (name, api.clone(), self.params.clone()))
.map(|(name, api, params)| async move {
api.delete(&name, &params).await?;
api.delete(name, &params).await?;
Ok::<_, kube::Error>(())
});
let smite_results = futures::future::join_all(smite_operations).await;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resource_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async fn clean_up_namespace(namespace: &str) -> Option<String> {
let namespaces: Api<Namespace> = Api::all(client.clone());

namespaces
.delete(&namespace, &DeleteParams::default())
.delete(namespace, &DeleteParams::default())
.await
.err()
.map(|e| format!("namespace {} ({})", namespace, e))
Expand Down

0 comments on commit 26ceb48

Please sign in to comment.