Skip to content

Commit 13d9b99

Browse files
committed
Verify we can use let-chains
after bumping image versions on e2e Signed-off-by: clux <[email protected]>
1 parent a4b799e commit 13d9b99

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

examples/pod_resize.rs

Lines changed: 23 additions & 25 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

@@ -48,10 +48,10 @@ async fn main() -> anyhow::Result<()> {
4848
// Example 1: Using get_resize to view current state
4949
info!("Example 1: Getting pod resize subresource");
5050
let current = pods.get_resize("resize-demo").await?;
51-
if let Some(spec) = &current.spec {
52-
if let Some(container) = spec.containers.first() {
53-
info!("Current resources: {:?}", container.resources);
54-
}
51+
if let Some(spec) = &current.spec
52+
&& let Some(container) = spec.containers.first()
53+
{
54+
info!("Current resources: {:?}", container.resources);
5555
}
5656

5757
// Example 2: Using patch_resize to update resources
@@ -81,10 +81,10 @@ async fn main() -> anyhow::Result<()> {
8181
{
8282
Ok(resized) => {
8383
info!("Successfully patched pod: {}", resized.name_any());
84-
if let Some(spec) = resized.spec {
85-
if let Some(container) = spec.containers.first() {
86-
info!("Updated resources via patch: {:?}", container.resources);
87-
}
84+
if let Some(spec) = resized.spec
85+
&& let Some(container) = spec.containers.first()
86+
{
87+
info!("Updated resources via patch: {:?}", container.resources);
8888
}
8989
}
9090
Err(e) => {
@@ -96,27 +96,25 @@ 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 {
114112
Ok(resized) => {
115113
info!("Pod resized via replace: {}", resized.name_any());
116-
if let Some(spec) = resized.spec {
117-
if let Some(container) = spec.containers.first() {
118-
info!("Final resources via replace: {:?}", container.resources);
119-
}
114+
if let Some(spec) = resized.spec
115+
&& let Some(container) = spec.containers.first()
116+
{
117+
info!("Final resources via replace: {:?}", container.resources);
120118
}
121119
}
122120
Err(e) => error!("Failed to replace_resize: {}", e),

kube-client/src/api/subresource.rs

Lines changed: 11 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,11 @@ 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+
/// // Update CPU/memory limits or requests
408+
/// // ...
409409
/// }
410410
///
411411
/// pods.replace_resize("mypod", &pp, &pod).await?;

0 commit comments

Comments
 (0)