@@ -30,13 +30,21 @@ pub enum Error {
3030 EmptyKubernetesNodesList ,
3131}
3232
33+ #[ derive( Debug , Deserialize ) ]
34+ #[ serde( rename_all = "camelCase" ) ]
35+ struct ProxyConfigResponse {
36+ kubeletconfig : KubeletConfig ,
37+ }
38+
3339#[ derive( Debug , Deserialize ) ]
3440#[ serde( rename_all = "camelCase" ) ]
3541pub struct KubeletConfig {
3642 pub cluster_domain : DomainName ,
3743}
3844
3945impl KubeletConfig {
46+
47+ /// Fetches the kubelet configuration from the "first" node in the Kubernetes cluster.
4048 pub async fn fetch ( client : & Client ) -> Result < Self , Error > {
4149 let api: Api < Node > = Api :: all ( client. clone ( ) ) ;
4250 let nodes = api
@@ -53,18 +61,11 @@ impl KubeletConfig {
5361 . body ( Default :: default ( ) )
5462 . context ( ConfigzRequestSnafu ) ?;
5563
56- // Deserialize JSON response as a JSON value. Alternatively, a type that
57- // implements `Deserialize` can be used.
5864 let resp = client
59- . request :: < serde_json :: Value > ( req)
65+ . request :: < ProxyConfigResponse > ( req)
6066 . await
6167 . context ( FetchNodeKubeletConfigSnafu { node : name } ) ?;
6268
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 )
6970 }
7071}
0 commit comments