Skip to content

Commit dc30de0

Browse files
committed
fix: use let chain instead of if let
Signed-off-by: hugoPonthieu <[email protected]>
1 parent de3b4f7 commit dc30de0

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

examples/pod_resize.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use k8s_openapi::api::core::v1::Pod;
22
use kube::{
3+
Client,
34
api::{Api, DeleteParams, Patch, PatchParams, PostParams, ResourceExt},
45
runtime::wait::{await_condition, conditions::is_pod_running},
5-
Client,
66
};
77
use tracing::*;
88

@@ -96,18 +96,16 @@ async fn main() -> anyhow::Result<()> {
9696
info!("Example 3: Using replace_resize method");
9797
let mut current_pod = pods.get_resize("resize-demo").await?;
9898

99-
if let Some(spec) = &mut current_pod.spec {
100-
if let Some(container) = spec.containers.get_mut(0) {
101-
if let Some(resources) = &mut container.resources {
102-
// Update memory request
103-
if let Some(requests) = &mut resources.requests {
104-
requests.insert(
105-
"memory".to_string(),
106-
k8s_openapi::apimachinery::pkg::api::resource::Quantity("384Mi".to_string()),
107-
);
108-
}
109-
}
110-
}
99+
if let Some(spec) = &mut current_pod.spec
100+
&& let Some(container) = spec.containers.get_mut(0)
101+
&& let Some(resources) = &mut container.resources
102+
&& let Some(requests) = &mut resources.requests
103+
{
104+
// Update memory request
105+
requests.insert(
106+
"memory".to_string(),
107+
k8s_openapi::apimachinery::pkg::api::resource::Quantity("384Mi".to_string()),
108+
);
111109
}
112110

113111
match pods.replace_resize("resize-demo", &pp, &current_pod).await {

kube-client/src/api/subresource.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use futures::AsyncBufRead;
2-
use serde::{de::DeserializeOwned, Serialize};
2+
use serde::{Serialize, de::DeserializeOwned};
33
use std::fmt::Debug;
44

55
use crate::{
6-
api::{Api, Patch, PatchParams, PostParams},
76
Error, Result,
7+
api::{Api, Patch, PatchParams, PostParams},
88
};
99

1010
use kube_core::response::Status;
@@ -16,8 +16,10 @@ pub use kube_core::subresource::AttachParams;
1616

1717
pub use k8s_openapi::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus};
1818

19-
#[cfg(feature = "ws")] use crate::api::portforward::Portforwarder;
20-
#[cfg(feature = "ws")] use crate::api::remote_command::AttachedProcess;
19+
#[cfg(feature = "ws")]
20+
use crate::api::portforward::Portforwarder;
21+
#[cfg(feature = "ws")]
22+
use crate::api::remote_command::AttachedProcess;
2123

2224
/// Methods for [scale subresource](https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#scale-subresource).
2325
impl<K> Api<K>
@@ -399,13 +401,12 @@ k8s_openapi::k8s_if_ge_1_33! {
399401
/// let mut pod = pods.get("mypod").await?;
400402
///
401403
/// // Modify resource requirements
402-
/// if let Some(spec) = &mut pod.spec {
403-
/// if let Some(container) = spec.containers.get_mut(0) {
404-
/// if let Some(resources) = &mut container.resources {
405-
/// // Update CPU/memory limits or requests
406-
/// // ...
407-
/// }
408-
/// }
404+
/// if let Some(spec) = &mut pod.spec
405+
/// && let Some(container) = spec.containers.get_mut(0)
406+
/// && let Some(resources) = &mut container.resources
407+
/// {
408+
/// // Update CPU/memory limits or requests
409+
/// // ...
409410
/// }
410411
///
411412
/// pods.replace_resize("mypod", &pp, &pod).await?;

0 commit comments

Comments
 (0)