11use std:: collections:: HashMap ;
22
3- use indicatif:: ProgressStyle ;
43use snafu:: { ResultExt , Snafu } ;
54use stackable_operator:: kvp:: Labels ;
6- use tracing:: { Instrument as _ , Span , debug, info, info_span , instrument} ;
5+ use tracing:: { Span , debug, info, instrument} ;
76use tracing_indicatif:: span_ext:: IndicatifSpanExt as _;
87
98use crate :: {
@@ -65,7 +64,7 @@ pub enum Error {
6564
6665pub trait InstallManifestsExt {
6766 // TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote
68- #[ instrument( skip_all, fields( %namespace) ) ]
67+ #[ instrument( skip_all, fields( %namespace, indicatif . pb_show = true ) ) ]
6968 #[ allow( async_fn_in_trait) ]
7069 async fn install_manifests (
7170 manifests : & [ ManifestSpec ] ,
@@ -86,94 +85,75 @@ pub trait InstallManifestsExt {
8685 parameters. insert ( "NAMESPACE" . to_owned ( ) , namespace. to_owned ( ) ) ;
8786
8887 for manifest in manifests {
89- let span = info_span ! ( "install_manifests_iter" ) ;
90-
9188 let parameters = parameters. clone ( ) ;
9289 let labels = labels. clone ( ) ;
93- async move {
94- match manifest {
95- ManifestSpec :: HelmChart ( helm_file) => {
96- debug ! ( helm_file, "Installing manifest from Helm chart" ) ;
97-
98- // Read Helm chart YAML and apply templating
99- let helm_file =
100- helm_file. into_path_or_url ( ) . context ( ParsePathOrUrlSnafu {
101- path_or_url : helm_file. clone ( ) ,
102- } ) ?;
10390
104- let helm_chart: helm:: Chart = transfer_client
105- . get ( & helm_file, & Template :: new ( & parameters) . then ( Yaml :: new ( ) ) )
106- . await
107- . context ( FileTransferSnafu ) ?;
108-
109- info ! ( helm_chart. name, helm_chart. version, "Installing Helm chart" , ) ;
110- Span :: current ( ) . pb_set_message (
111- format ! ( "Installing {name} Helm chart" , name = helm_chart. name)
112- . as_str ( ) ,
113- ) ;
114- Span :: current ( ) . pb_set_style (
115- & ProgressStyle :: with_template ( "{spinner} {msg}" )
116- . expect ( "valid progress template" ) ,
117- ) ;
118-
119- // Assumption: that all manifest helm charts refer to repos not registries
120- helm:: add_repo ( & helm_chart. repo . name , & helm_chart. repo . url ) . context (
121- AddHelmRepositorySnafu {
122- repo_name : helm_chart. repo . name . clone ( ) ,
123- } ,
124- ) ?;
125-
126- // Serialize chart options to string
127- let values_yaml = serde_yaml:: to_string ( & helm_chart. options )
128- . context ( SerializeOptionsSnafu ) ?;
129-
130- // Install the Helm chart using the Helm wrapper
131- helm:: install_release_from_repo_or_registry (
132- & helm_chart. release_name ,
133- helm:: ChartVersion {
134- chart_source : & helm_chart. repo . name ,
135- chart_name : & helm_chart. name ,
136- chart_version : Some ( & helm_chart. version ) ,
137- } ,
138- Some ( & values_yaml) ,
139- namespace,
140- true ,
141- )
142- . context ( InstallHelmReleaseSnafu {
143- release_name : helm_chart. release_name ,
91+ match manifest {
92+ ManifestSpec :: HelmChart ( helm_file) => {
93+ debug ! ( helm_file, "Installing manifest from Helm chart" ) ;
94+
95+ // Read Helm chart YAML and apply templating
96+ let helm_file =
97+ helm_file. into_path_or_url ( ) . context ( ParsePathOrUrlSnafu {
98+ path_or_url : helm_file. clone ( ) ,
14499 } ) ?;
145- }
146- ManifestSpec :: PlainYaml ( manifest_file) => {
147- debug ! ( manifest_file, "Installing YAML manifest" ) ;
148- Span :: current ( ) . pb_set_style (
149- & ProgressStyle :: with_template ( "{spinner} Installing YAML manifest" )
150- . expect ( "valid progress template" ) ,
151- ) ;
152-
153- // Read YAML manifest and apply templating
154- let path_or_url =
155- manifest_file
156- . into_path_or_url ( )
157- . context ( ParsePathOrUrlSnafu {
158- path_or_url : manifest_file. clone ( ) ,
159- } ) ?;
160-
161- let manifests = transfer_client
162- . get ( & path_or_url, & Template :: new ( & parameters) )
163- . await
164- . context ( FileTransferSnafu ) ?;
165-
166- client
167- . deploy_manifests ( & manifests, namespace, labels. clone ( ) )
168- . await
169- . context ( DeployManifestSnafu ) ?;
170- }
100+
101+ let helm_chart: helm:: Chart = transfer_client
102+ . get ( & helm_file, & Template :: new ( & parameters) . then ( Yaml :: new ( ) ) )
103+ . await
104+ . context ( FileTransferSnafu ) ?;
105+
106+ info ! ( helm_chart. name, helm_chart. version, "Installing Helm chart" , ) ;
107+
108+ // Assumption: that all manifest helm charts refer to repos not registries
109+ helm:: add_repo ( & helm_chart. repo . name , & helm_chart. repo . url ) . context (
110+ AddHelmRepositorySnafu {
111+ repo_name : helm_chart. repo . name . clone ( ) ,
112+ } ,
113+ ) ?;
114+
115+ // Serialize chart options to string
116+ let values_yaml = serde_yaml:: to_string ( & helm_chart. options )
117+ . context ( SerializeOptionsSnafu ) ?;
118+
119+ // Install the Helm chart using the Helm wrapper
120+ helm:: install_release_from_repo_or_registry (
121+ & helm_chart. release_name ,
122+ helm:: ChartVersion {
123+ chart_source : & helm_chart. repo . name ,
124+ chart_name : & helm_chart. name ,
125+ chart_version : Some ( & helm_chart. version ) ,
126+ } ,
127+ Some ( & values_yaml) ,
128+ namespace,
129+ true ,
130+ )
131+ . context ( InstallHelmReleaseSnafu {
132+ release_name : helm_chart. release_name ,
133+ } ) ?;
171134 }
135+ ManifestSpec :: PlainYaml ( manifest_file) => {
136+ debug ! ( manifest_file, "Installing YAML manifest" ) ;
137+
138+ // Read YAML manifest and apply templating
139+ let path_or_url =
140+ manifest_file
141+ . into_path_or_url ( )
142+ . context ( ParsePathOrUrlSnafu {
143+ path_or_url : manifest_file. clone ( ) ,
144+ } ) ?;
145+
146+ let manifests = transfer_client
147+ . get ( & path_or_url, & Template :: new ( & parameters) )
148+ . await
149+ . context ( FileTransferSnafu ) ?;
172150
173- Ok :: < ( ) , Error > ( ( ) )
151+ client
152+ . deploy_manifests ( & manifests, namespace, labels. clone ( ) )
153+ . await
154+ . context ( DeployManifestSnafu ) ?;
155+ }
174156 }
175- . instrument ( span)
176- . await ?;
177157
178158 Span :: current ( ) . pb_inc ( 1 ) ;
179159 }
0 commit comments