1
1
use 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 ;
8
3
use serde:: Deserialize ;
9
- use snafu:: { OptionExt , ResultExt , Snafu } ;
4
+ use snafu:: { ResultExt , Snafu } ;
10
5
11
6
use crate :: commons:: networking:: DomainName ;
12
7
13
8
#[ derive( Debug , Snafu ) ]
14
9
pub enum Error {
15
- #[ snafu( display( "failed to list nodes" ) ) ]
16
- ListNodes { source : kube:: Error } ,
17
-
18
10
#[ snafu( display( "failed to build request for url path \" {url_path}\" " ) ) ]
19
11
BuildConfigzRequest {
20
12
source : http:: Error ,
@@ -29,11 +21,6 @@ pub enum Error {
29
21
30
22
#[ snafu( display( "failed to deserialize kubelet config JSON" ) ) ]
31
23
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 ,
37
24
}
38
25
39
26
#[ derive( Debug , Deserialize ) ]
@@ -49,16 +36,8 @@ pub struct KubeletConfig {
49
36
}
50
37
51
38
impl 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 > {
62
41
let url_path = format ! ( "/api/v1/nodes/{node_name}/proxy/configz" ) ;
63
42
let req = http:: Request :: get ( url_path. clone ( ) )
64
43
. body ( Default :: default ( ) )
0 commit comments