@@ -30,13 +30,21 @@ pub enum Error {
30
30
EmptyKubernetesNodesList ,
31
31
}
32
32
33
+ #[ derive( Debug , Deserialize ) ]
34
+ #[ serde( rename_all = "camelCase" ) ]
35
+ struct ProxyConfigResponse {
36
+ kubeletconfig : KubeletConfig ,
37
+ }
38
+
33
39
#[ derive( Debug , Deserialize ) ]
34
40
#[ serde( rename_all = "camelCase" ) ]
35
41
pub struct KubeletConfig {
36
42
pub cluster_domain : DomainName ,
37
43
}
38
44
39
45
impl KubeletConfig {
46
+
47
+ /// Fetches the kubelet configuration from the "first" node in the Kubernetes cluster.
40
48
pub async fn fetch ( client : & Client ) -> Result < Self , Error > {
41
49
let api: Api < Node > = Api :: all ( client. clone ( ) ) ;
42
50
let nodes = api
@@ -53,18 +61,11 @@ impl KubeletConfig {
53
61
. body ( Default :: default ( ) )
54
62
. context ( ConfigzRequestSnafu ) ?;
55
63
56
- // Deserialize JSON response as a JSON value. Alternatively, a type that
57
- // implements `Deserialize` can be used.
58
64
let resp = client
59
- . request :: < serde_json :: Value > ( req)
65
+ . request :: < ProxyConfigResponse > ( req)
60
66
. await
61
67
. context ( FetchNodeKubeletConfigSnafu { node : name } ) ?;
62
68
63
- // Our JSON value is an object so we can treat it like a dictionary.
64
- let summary = resp
65
- . get ( "kubeletconfig" )
66
- . context ( KubeletConfigJsonKeySnafu ) ?;
67
-
68
- serde_json:: from_value :: < KubeletConfig > ( summary. to_owned ( ) ) . context ( KubeletConfigJsonSnafu )
69
+ Ok ( resp. kubeletconfig )
69
70
}
70
71
}
0 commit comments