1
1
use crate :: { Client , Error , Result } ;
2
2
use k8s_openapi:: {
3
- api:: {
4
- core:: v1:: { LocalObjectReference , Namespace as k8sNs, ObjectReference } ,
5
- } ,
3
+ api:: core:: v1:: { LocalObjectReference , Namespace as k8sNs, ObjectReference } ,
6
4
apimachinery:: pkg:: apis:: meta:: v1:: OwnerReference ,
7
5
} ;
8
6
use kube_core:: {
9
7
object:: ObjectList ,
10
8
params:: { GetParams , ListParams , Patch , PatchParams } ,
11
9
request:: Request ,
12
- ApiResource , ClusterResourceScope , DynamicResourceScope , NamespaceResourceScope , ObjectMeta , Resource ,
13
- ResourceExt ,
10
+ ApiResource , ClusterResourceScope , DynamicResourceScope , NamespaceResourceScope , Resource , ResourceExt ,
11
+ TypeMeta ,
14
12
} ;
15
13
use serde:: { de:: DeserializeOwned , Serialize } ;
16
14
use std:: fmt:: Debug ;
@@ -233,6 +231,18 @@ pub enum NamespaceError {
233
231
MissingName ,
234
232
}
235
233
234
+ #[ derive( Serialize , Clone , Debug ) ]
235
+ /// ApplyObject allows to wrap an object into Patch::Apply compatible structure,
236
+ /// with populated TypeMeta.
237
+ pub struct ApplyObject < R : Serialize > {
238
+ /// Contains the API version and type of the request.
239
+ #[ serde( flatten) ]
240
+ pub types : TypeMeta ,
241
+ /// Contains the object data.
242
+ #[ serde( flatten) ]
243
+ pub data : R ,
244
+ }
245
+
236
246
/// Generic client extensions for the `unstable-client` feature
237
247
///
238
248
/// These methods allow users to query across a wide-array of resources without needing
@@ -390,7 +400,7 @@ impl Client {
390
400
/// Perform apply patch on the provided `Resource` implementing type `K`
391
401
///
392
402
/// ```no_run
393
- /// # use k8s_openapi::api::core::v1::;
403
+ /// # use k8s_openapi::api::core::v1::Pod ;
394
404
/// # use k8s_openapi::api::core::v1::Service;
395
405
/// # use kube::client::scope::Namespace;
396
406
/// # use kube::prelude::*;
@@ -404,7 +414,7 @@ impl Client {
404
414
/// # Ok(())
405
415
/// # }
406
416
/// ```
407
- pub async fn apply < K , P : Serialize + Debug > ( & self , resource : & K , pp : & PatchParams ) -> Result < K >
417
+ pub async fn apply < K > ( & self , resource : & K , pp : & PatchParams ) -> Result < K >
408
418
where
409
419
K : ResourceExt + Serialize + DeserializeOwned + Clone + Debug ,
410
420
<K as Resource >:: DynamicType : Default ,
@@ -414,10 +424,17 @@ impl Client {
414
424
let url = K :: url_path ( & Default :: default ( ) , meta. namespace . as_deref ( ) ) ;
415
425
let req = Request :: new ( url) ;
416
426
417
- let mut resource = resource. clone ( ) ;
418
- resource. meta_mut ( ) . managed_fields = None ;
419
- let patch = & Patch :: Apply ( resource) ;
420
- let req = req. patch ( name, pp, patch) . map_err ( Error :: BuildRequest ) ?;
427
+ let apply = ApplyObject :: < K > {
428
+ types : TypeMeta :: resource :: < K > ( ) ,
429
+ data : {
430
+ let mut resource = resource. clone ( ) ;
431
+ resource. meta_mut ( ) . managed_fields = None ;
432
+ resource
433
+ } ,
434
+ } ;
435
+ let req = req
436
+ . patch ( name, pp, & Patch :: Apply ( apply) )
437
+ . map_err ( Error :: BuildRequest ) ?;
421
438
self . request :: < K > ( req) . await
422
439
}
423
440
@@ -438,7 +455,7 @@ impl Client {
438
455
/// # Ok(())
439
456
/// # }
440
457
/// ```
441
- pub async fn apply_status < K , P : Serialize + Debug > ( & self , resource : & K , pp : & PatchParams ) -> Result < K >
458
+ pub async fn apply_status < K > ( & self , resource : & K , pp : & PatchParams ) -> Result < K >
442
459
where
443
460
K : ResourceExt + Serialize + DeserializeOwned + Clone + Debug ,
444
461
<K as Resource >:: DynamicType : Default ,
@@ -448,11 +465,16 @@ impl Client {
448
465
let url = K :: url_path ( & Default :: default ( ) , meta. namespace . as_deref ( ) ) ;
449
466
let req = Request :: new ( url) ;
450
467
451
- let mut resource = resource. clone ( ) ;
452
- resource. meta_mut ( ) . managed_fields = None ;
453
- let patch = & Patch :: Apply ( resource) ;
468
+ let apply = ApplyObject :: < K > {
469
+ types : TypeMeta :: resource :: < K > ( ) ,
470
+ data : {
471
+ let mut resource = resource. clone ( ) ;
472
+ resource. meta_mut ( ) . managed_fields = None ;
473
+ resource
474
+ } ,
475
+ } ;
454
476
let req = req
455
- . patch_subresource ( "status" , name, pp, patch )
477
+ . patch_subresource ( "status" , name, pp, & Patch :: Apply ( apply ) )
456
478
. map_err ( Error :: BuildRequest ) ?;
457
479
self . request :: < K > ( req) . await
458
480
}
0 commit comments