@@ -37,13 +37,9 @@ pub struct SupportArgs {
3737 #[ clap( global = true , long, short = 'd' , default_value = "./" ) ]
3838 output_directory_path : String ,
3939
40- /// Kubernetes namespace of mayastor service
41- #[ clap( global = true , long, short = 'n' , default_value = "mayastor" ) ]
42- namespace : String ,
43-
44- /// Path to kubeconfig file.
40+ /// K8s connection context arguments.
4541 #[ clap( skip) ]
46- kubeconfig : KubeConfigArgs ,
42+ ctx : K8sCtxArgs ,
4743
4844 /// The tenant id to be used to query loki logs.
4945 #[ clap( global = true , long, default_value = "openebs" ) ]
@@ -62,14 +58,18 @@ impl SupportArgs {
6258 /// * `path` - An optional `PathBuf` representing the kubeconfig path.
6359 /// * `context` - An optional context in the kubeconfig file.
6460 pub fn set_kube_config ( & mut self , path : Option < std:: path:: PathBuf > , context : Option < String > ) {
65- self . kubeconfig = crate :: KubeConfigArgs {
61+ self . ctx . kubeconfig = crate :: KubeConfigArgs {
6662 path,
6763 opts : kube:: config:: KubeConfigOptions {
6864 context,
6965 ..Default :: default ( )
7066 } ,
7167 } ;
7268 }
69+ /// Sets the namespace of the target install.
70+ pub fn set_namespace ( & mut self , namespace : String ) {
71+ self . ctx . namespace = namespace;
72+ }
7373}
7474
7575/// Supportability - collects state & log information of services and dumps it to a tar file.
@@ -86,10 +86,15 @@ pub struct DumpArgs {
8686
8787#[ async_trait:: async_trait( ?Send ) ]
8888impl ExecuteOperation for DumpArgs {
89- type Args = ( ) ;
89+ type Args = K8sCtxArgs ;
9090 type Error = anyhow:: Error ;
91- async fn execute ( & self , _cli_args : & Self :: Args ) -> Result < ( ) , Self :: Error > {
92- self . resource . execute ( & self . args ) . await
91+ async fn execute ( & self , cli_args : & Self :: Args ) -> Result < ( ) , Self :: Error > {
92+ let args = SupportArgs {
93+ ctx : cli_args. clone ( ) ,
94+ ..self . args . clone ( )
95+ } ;
96+
97+ self . resource . execute ( & args) . await
9398 }
9499}
95100
@@ -99,7 +104,7 @@ impl ExecuteOperation for Resource {
99104 type Error = anyhow:: Error ;
100105
101106 async fn execute ( & self , cli_args : & Self :: Args ) -> Result < ( ) , Self :: Error > {
102- execute_resource_dump ( cli_args. clone ( ) , cli_args . kubeconfig . clone ( ) , self . clone ( ) )
107+ execute_resource_dump ( cli_args. clone ( ) , self . clone ( ) )
103108 . await
104109 . map_err ( |e| anyhow:: anyhow!( "{:?}" , e) )
105110 }
@@ -108,18 +113,14 @@ impl ExecuteOperation for Resource {
108113// Holds prefix of archive file name
109114pub ( crate ) const ARCHIVE_PREFIX : & str = "mayastor" ;
110115
111- async fn execute_resource_dump (
112- cli_args : SupportArgs ,
113- kubeconfig : crate :: KubeConfigArgs ,
114- resource : Resource ,
115- ) -> Result < ( ) , Error > {
116+ async fn execute_resource_dump ( cli_args : SupportArgs , resource : Resource ) -> Result < ( ) , Error > {
116117 let mut config = DumpConfig :: new (
117118 cli_args. output_directory_path ,
118- cli_args. namespace ,
119+ cli_args. ctx . namespace ,
119120 cli_args. loki_endpoint ,
120121 cli_args. etcd_endpoint ,
121122 cli_args. since ,
122- kubeconfig,
123+ cli_args . ctx . kubeconfig ,
123124 cli_args. timeout ,
124125 OutputFormat :: Tar ,
125126 cli_args. tenant_id ,
@@ -200,6 +201,20 @@ impl std::fmt::Debug for KubeConfigArgs {
200201 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
201202 f. debug_struct ( "KubeConfigOpts" )
202203 . field ( "kubeconfig" , & self . path )
204+ . field ( "cluster" , & self . opts . cluster )
205+ . field ( "context" , & self . opts . context )
206+ . field ( "user" , & self . opts . user )
203207 . finish ( )
204208 }
205209}
210+
211+ /// K8s contextual arguments.
212+ #[ derive( Default , Debug , Clone ) ]
213+ pub struct K8sCtxArgs {
214+ /// The namespace where we're installed.
215+ pub namespace : String ,
216+ /// Options used when loading the kubeconfig file.
217+ /// This is necessary because the existing code uses these directly, even though the
218+ /// initial connection and context namespace is retrieved at the start.
219+ pub kubeconfig : KubeConfigArgs ,
220+ }
0 commit comments