11use k8s_openapi:: api:: core:: v1:: Pod ;
22use kube:: {
3+ Client ,
34 api:: { Api , DeleteParams , Patch , PatchParams , PostParams , ResourceExt } ,
45 runtime:: wait:: { await_condition, conditions:: is_pod_running} ,
5- Client ,
66} ;
77use 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) ,
0 commit comments