1- use colored:: Colorize ;
2- use kube:: { core:: ErrorResponse } ;
3- use clap:: { Args , Subcommand , command } ;
4- use std:: { process:: { Command } , thread, time:: Duration } ;
5- use crate :: {
6- essential:: { connect_to_client, create_config_file, create_configs, BASE_COMMAND , CliError } ,
1+ use crate :: essential:: {
2+ BASE_COMMAND , CliError , connect_to_client, create_config_file, create_configs,
73} ;
4+ use clap:: { Args , Subcommand , command} ;
5+ use colored:: Colorize ;
86use kube:: Error ;
7+ use kube:: core:: ErrorResponse ;
8+ use std:: { process:: Command , thread, time:: Duration } ;
99
1010// docs:
1111//
@@ -29,7 +29,10 @@ enum InstallationType {
2929
3030#[ derive( Subcommand , Debug , Clone ) ]
3131pub enum InstallCommands {
32- #[ command( name = "cortexflow" , about = "Install all the CortexBrain core components" ) ]
32+ #[ command(
33+ name = "cortexflow" ,
34+ about = "Install all the CortexBrain core components"
35+ ) ]
3336 All ,
3437 #[ command(
3538 name = "simple-example" ,
@@ -51,9 +54,21 @@ pub struct InstallArgs {
5154// This function creates the cortexflow namespace, manages the metadata file creation and removes the temporary installation files
5255
5356pub async fn install_cortexflow ( ) -> Result < ( ) , CliError > {
54- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Preparing cortexflow installation" . white( ) ) ;
55- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Creating the config files" . white( ) ) ;
56- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Creating cortexflow namespace" . white( ) ) ;
57+ println ! (
58+ "{} {}" ,
59+ "=====>" . blue( ) . bold( ) ,
60+ "Preparing cortexflow installation" . white( )
61+ ) ;
62+ println ! (
63+ "{} {}" ,
64+ "=====>" . blue( ) . bold( ) ,
65+ "Creating the config files" . white( )
66+ ) ;
67+ println ! (
68+ "{} {}" ,
69+ "=====>" . blue( ) . bold( ) ,
70+ "Creating cortexflow namespace" . white( )
71+ ) ;
5772 Command :: new ( "kubectl" )
5873 . args ( [ "create" , "namespace" , "cortexflow" ] )
5974 . output ( )
@@ -71,7 +86,11 @@ pub async fn install_cortexflow() -> Result<(), CliError> {
7186// This function installs the demostration examples
7287
7388pub async fn install_simple_example ( ) -> Result < ( ) , CliError > {
74- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Installing simple example" . white( ) ) ;
89+ println ! (
90+ "{} {}" ,
91+ "=====>" . blue( ) . bold( ) ,
92+ "Installing simple example" . white( )
93+ ) ;
7594 install_simple_example_component ( ) . await ?;
7695 Ok ( ( ) )
7796}
@@ -90,47 +109,47 @@ pub async fn install_simple_example() -> Result<(), CliError> {
90109async fn install_cluster_components ( ) -> Result < ( ) , CliError > {
91110 match connect_to_client ( ) . await {
92111 Ok ( _) => {
93- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Copying installation files" . white( ) ) ;
112+ println ! (
113+ "{} {}" ,
114+ "=====>" . blue( ) . bold( ) ,
115+ "Copying installation files" . white( )
116+ ) ;
94117 download_installation_files (
95118 InstallationType :: Components (
96119 vec ! [
97120 "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/configmap-role.yaml" . to_string( ) ,
98121 "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/rolebinding.yaml" . to_string( ) ,
99122 "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/cortexflow-rolebinding.yaml" . to_string( ) ,
100- "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/feature/ebpf-core/core/src/testing/identity.yaml" . to_string( ) ,
101- "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/feature/ebpf-core/core/src/testing/agent.yaml" . to_string( )
123+ "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/identity.yaml" . to_string( ) ,
124+ "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/agent.yaml" . to_string( ) ,
125+ "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/main/core/src/testing/metrics.yaml" . to_string( )
102126 ]
103127 )
104128 ) ?;
105129 thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
106130 install_components ( "cortexbrain" ) ?;
107131 println ! ( "\n " ) ;
108- rm_installation_files (
109- InstallationType :: Components (
110- vec ! [
111- "configmap-role.yaml" . to_string( ) ,
112- "rolebinding.yaml" . to_string( ) ,
113- "cortexflow-rolebinding.yaml" . to_string( ) ,
114- "identity.yaml" . to_string( ) ,
115- "agent.yaml" . to_string( )
116- ]
117- )
118- ) ?;
119- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "installation completed" . white( ) ) ;
132+ rm_installation_files ( InstallationType :: Components ( vec ! [
133+ "configmap-role.yaml" . to_string( ) ,
134+ "rolebinding.yaml" . to_string( ) ,
135+ "cortexflow-rolebinding.yaml" . to_string( ) ,
136+ "identity.yaml" . to_string( ) ,
137+ "metrics.yaml" . to_string( ) ,
138+ "agent.yaml" . to_string( ) ,
139+ ] ) ) ?;
140+ println ! (
141+ "{} {}" ,
142+ "=====>" . blue( ) . bold( ) ,
143+ "installation completed" . white( )
144+ ) ;
120145 Ok ( ( ) )
121146 }
122- Err ( e) => {
123- Err (
124- CliError :: ClientError (
125- Error :: Api ( ErrorResponse {
126- status : "failed" . to_string ( ) ,
127- message : "Failed to connect to kubernetes client" . to_string ( ) ,
128- reason : "Your cluster is probably disconnected" . to_string ( ) ,
129- code : 404 ,
130- } )
131- )
132- )
133- }
147+ Err ( e) => Err ( CliError :: ClientError ( Error :: Api ( ErrorResponse {
148+ status : "failed" . to_string ( ) ,
149+ message : "Failed to connect to kubernetes client" . to_string ( ) ,
150+ reason : "Your cluster is probably disconnected" . to_string ( ) ,
151+ code : 404 ,
152+ } ) ) ) ,
134153 }
135154}
136155
@@ -148,7 +167,11 @@ async fn install_cluster_components() -> Result<(), CliError> {
148167async fn install_simple_example_component ( ) -> Result < ( ) , CliError > {
149168 match connect_to_client ( ) . await {
150169 Ok ( _) => {
151- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Copying installation files" . white( ) ) ;
170+ println ! (
171+ "{} {}" ,
172+ "=====>" . blue( ) . bold( ) ,
173+ "Copying installation files" . white( )
174+ ) ;
152175 download_installation_files (
153176 InstallationType :: SimpleExample (
154177 "https://raw.githubusercontent.com/CortexFlow/CortexBrain/refs/heads/feature/ebpf-core/core/src/testing/deploy-test-pod.yaml" . to_string ( )
@@ -157,24 +180,22 @@ async fn install_simple_example_component() -> Result<(), CliError> {
157180 thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
158181 install_components ( "simple-example" ) ?;
159182 println ! ( "\n " ) ;
160- rm_installation_files (
161- InstallationType :: SimpleExample ( "deploy-test-pod.yaml" . to_string ( ) )
162- ) ?;
163- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "installation completed" . white( ) ) ;
183+ rm_installation_files ( InstallationType :: SimpleExample (
184+ "deploy-test-pod.yaml" . to_string ( ) ,
185+ ) ) ?;
186+ println ! (
187+ "{} {}" ,
188+ "=====>" . blue( ) . bold( ) ,
189+ "installation completed" . white( )
190+ ) ;
164191 Ok ( ( ) )
165192 }
166- Err ( e) => {
167- Err (
168- CliError :: ClientError (
169- Error :: Api ( ErrorResponse {
170- status : "failed" . to_string ( ) ,
171- message : "Failed to connect to kubernetes client" . to_string ( ) ,
172- reason : "Your cluster is probably disconnected" . to_string ( ) ,
173- code : 404 ,
174- } )
175- )
176- )
177- }
193+ Err ( e) => Err ( CliError :: ClientError ( Error :: Api ( ErrorResponse {
194+ status : "failed" . to_string ( ) ,
195+ message : "Failed to connect to kubernetes client" . to_string ( ) ,
196+ reason : "Your cluster is probably disconnected" . to_string ( ) ,
197+ code : 404 ,
198+ } ) ) ) ,
178199 }
179200}
180201
@@ -193,24 +214,29 @@ fn install_components(components_type: &str) -> Result<(), CliError> {
193214 "rolebinding.yaml" ,
194215 "cortexflow-rolebinding.yaml" ,
195216 "identity.yaml" ,
196- "agent.yaml"
217+ "metrics.yaml" ,
218+ "agent.yaml" ,
197219 ] ;
198220 let tot_files = files_to_install. len ( ) ;
199221
200- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Installing cortexflow components" . white( ) ) ;
222+ println ! (
223+ "{} {}" ,
224+ "=====>" . blue( ) . bold( ) ,
225+ "Installing cortexflow components" . white( )
226+ ) ;
201227 let mut i = 1 ;
202228
203229 for component in files_to_install {
204230 println ! (
205- "{} {}{}{}{} {} {} {}" ,
231+ "{} {}{}{}{}{} {} {}" ,
206232 "=====>" . blue( ) . bold( ) ,
207233 "(" ,
208234 i,
209235 "/" ,
210236 tot_files,
211237 ")" ,
212- "Applying " ,
213- component
238+ "Applying" ,
239+ component. to_string ( ) . green ( ) . bold ( )
214240 ) ;
215241 apply_component ( component) ;
216242 i = i + 1 ;
@@ -222,15 +248,15 @@ fn install_components(components_type: &str) -> Result<(), CliError> {
222248
223249 for component in files_to_install {
224250 println ! (
225- "{} {}{}{}{} {} {} {}" ,
251+ "{} {}{}{}{}{} {} {}" ,
226252 "=====>" . blue( ) . bold( ) ,
227253 "(" ,
228254 i,
229255 "/" ,
230256 tot_files,
231257 ")" ,
232- "Applying " ,
233- component
258+ "Applying" ,
259+ component. to_string ( ) . green ( ) . bold ( )
234260 ) ;
235261 apply_component ( component) ;
236262 i = i + 1 ;
@@ -261,7 +287,11 @@ fn apply_component(file: &str) -> Result<(), CliError> {
261287 } ) ?;
262288
263289 if !output. status . success ( ) {
264- eprintln ! ( "Error installing file: {}:\n {}" , file, String :: from_utf8_lossy( & output. stderr) ) ;
290+ eprintln ! (
291+ "Error installing file: {}:\n {}" ,
292+ file,
293+ String :: from_utf8_lossy( & output. stderr)
294+ ) ;
265295 } else {
266296 println ! ( "✅ Applied {}" , file) ;
267297 }
@@ -303,7 +333,11 @@ fn download_installation_files(installation_files: InstallationType) -> Result<(
303333// Returns an CliError if something fails
304334
305335fn rm_installation_files ( file_to_remove : InstallationType ) -> Result < ( ) , CliError > {
306- println ! ( "{} {}" , "=====>" . blue( ) . bold( ) , "Removing temporary installation files" . white( ) ) ;
336+ println ! (
337+ "{} {}" ,
338+ "=====>" . blue( ) . bold( ) ,
339+ "Removing temporary installation files" . white( )
340+ ) ;
307341 match file_to_remove {
308342 InstallationType :: Components ( files) => {
309343 for src in files. iter ( ) {
@@ -328,15 +362,20 @@ fn rm_installation_files(file_to_remove: InstallationType) -> Result<(), CliErro
328362// Returns a CliError if something fails
329363
330364fn download_file ( src : & str ) -> Result < ( ) , CliError > {
331- let output = Command :: new ( "wget" )
332- . args ( [ src] )
333- . output ( )
334- . map_err ( |_| CliError :: InstallerError {
335- reason : "An error occured: component download failed" . to_string ( ) ,
336- } ) ?;
365+ let output =
366+ Command :: new ( "wget" )
367+ . args ( [ src] )
368+ . output ( )
369+ . map_err ( |_| CliError :: InstallerError {
370+ reason : "An error occured: component download failed" . to_string ( ) ,
371+ } ) ?;
337372
338373 if !output. status . success ( ) {
339- eprintln ! ( "Error copying file: {}.\n {}" , src, String :: from_utf8_lossy( & output. stderr) ) ;
374+ eprintln ! (
375+ "Error copying file: {}.\n {}" ,
376+ src,
377+ String :: from_utf8_lossy( & output. stderr)
378+ ) ;
340379 } else {
341380 println ! ( "✅ Copied file from {} " , src) ;
342381 }
0 commit comments