11use http;
2- use k8s_openapi:: api:: core:: v1:: Node ;
3- use kube:: {
4- Api ,
5- api:: { ListParams , ResourceExt } ,
6- client:: Client ,
7- } ;
2+ use kube:: client:: Client ;
83use serde:: Deserialize ;
9- use snafu:: { OptionExt , ResultExt , Snafu } ;
4+ use snafu:: { ResultExt , Snafu } ;
105
116use crate :: commons:: networking:: DomainName ;
127
138#[ derive( Debug , Snafu ) ]
149pub enum Error {
15- #[ snafu( display( "failed to list nodes" ) ) ]
16- ListNodes { source : kube:: Error } ,
17-
1810 #[ snafu( display( "failed to build request for url path \" {url_path}\" " ) ) ]
1911 BuildConfigzRequest {
2012 source : http:: Error ,
@@ -29,11 +21,6 @@ pub enum Error {
2921
3022 #[ snafu( display( "failed to deserialize kubelet config JSON" ) ) ]
3123 KubeletConfigJson { source : serde_json:: Error } ,
32-
33- #[ snafu( display(
34- "empty Kubernetes nodes list. At least one node is required to fetch the cluster domain from the kubelet config"
35- ) ) ]
36- EmptyKubernetesNodesList ,
3724}
3825
3926#[ derive( Debug , Deserialize ) ]
@@ -49,16 +36,8 @@ pub struct KubeletConfig {
4936}
5037
5138impl KubeletConfig {
52- /// Fetches the kubelet configuration from the "first" node in the Kubernetes cluster.
53- pub async fn fetch ( client : & Client ) -> Result < Self , Error > {
54- let api: Api < Node > = Api :: all ( client. clone ( ) ) ;
55- let nodes = api
56- . list ( & ListParams :: default ( ) )
57- . await
58- . context ( ListNodesSnafu ) ?;
59- let node = nodes. iter ( ) . next ( ) . context ( EmptyKubernetesNodesListSnafu ) ?;
60- let node_name = node. name_any ( ) ;
61-
39+ /// Fetches the kubelet configuration from the specified node in the Kubernetes cluster.
40+ pub async fn fetch ( client : & Client , node_name : & str ) -> Result < Self , Error > {
6241 let url_path = format ! ( "/api/v1/nodes/{node_name}/proxy/configz" ) ;
6342 let req = http:: Request :: get ( url_path. clone ( ) )
6443 . body ( Default :: default ( ) )
0 commit comments