@@ -7,7 +7,7 @@ import * as imm from "immutable";
77import * as k8s from "@kubernetes/client-node" ;
88import jmp from "json-merge-patch" ;
99import rx from "rxjs" ;
10- import template from "json-templates" ;
10+ import compile_template from "json-templates" ;
1111
1212import * as rxx from "@amrc-factoryplus/rx-util" ;
1313
@@ -127,16 +127,13 @@ export class Deployments {
127127 * chance the ACS deployment ever changes. */
128128 const git = rxx . rx (
129129 rx . timer ( 0 , 2 * 60 * 60 * 1000 ) ,
130- rx . tap ( ( ) => this . log ( "Fetching Git base URL" ) ) ,
131130 rx . exhaustMap ( ( ) => this . fplus . Git . base_url ( ) ) ,
132131 rx . distinctUntilChanged ( ) ,
133132 rx . tap ( b => this . log ( "New Git base: %s" , b ) ) ,
134- rx . map ( base => uuid => new URL ( `uuid/${ uuid } ` , base ) . toString ( ) ) ,
135- rx . tap ( f => this . log ( "Git base map: %o" , f ) ) ) ;
133+ rx . map ( base => uuid => new URL ( `uuid/${ uuid } ` , base ) . toString ( ) ) ) ;
136134
137135 const k8s = rxx . rx (
138136 cdb . watch_config ( app , app ) ,
139- rx . tap ( v => this . log ( "Raw config: %o" , v ) ) ,
140137 rx . map ( conf => ( {
141138 /* We must explicitly list the resource types we are
142139 * managing to handle the case where all resources of a
@@ -148,7 +145,7 @@ export class Deployments {
148145 apiVersion : "source.toolkit.fluxcd.io/v1" ,
149146 kind : "GitRepository" ,
150147 } ) ) ,
151- template : template ( conf . template ) ,
148+ template : compile_template ( conf . template ) ,
152149 } ) ) ,
153150 rx . tap ( c => this . log ( "Config: %o" , c ) ) ) ;
154151
@@ -159,54 +156,49 @@ export class Deployments {
159156 const { Deployments, HelmChart } = Edge . App ;
160157 const cdb = this . fplus . ConfigDB ;
161158
162- /* Take a list of Deployment entry UUIDs. Look up the Deployment
163- * entries (preserving the entry UUID), and then look up and
164- * compile the Helm Chart templates referenced from there.
165- * Returns an array of individual charts which need to be
166- * deployed. */
167- const lookup = map => rx . from ( map ) . pipe (
168- rx . map ( ( [ uuid , spec ] ) => ( { uuid, spec } ) ) ,
169- // Extract the chart UUIDs from the deployment
170- rx . map ( dep => {
171- const { spec } = dep ;
172- // XXX - The support for the charts key is deprecated
173- // and will be removed in a future version. This is here
174- // for backward compatibility. New deployments should
175- // use the chart key instead.
176- //
177- // Handle both single chart and multiple charts
178- const charts =
179- spec . chart ? rx . of ( spec . chart ) : rx . from ( spec . charts ?? [ ] ) ;
180- return [ dep , charts ] ;
181- } ) ,
182- // For each chart UUID, get the chart template and extract the source
183- rx . mergeMap ( ( [ deployment , charts ] ) => charts . pipe (
184- // Get the chart template configuration using the chart UUID
185- /* XXX We should track these via notify */
186- rx . mergeMap ( ch => cdb . get_config ( HelmChart , ch ) ) ,
187- rx . map ( tmpl => ( {
188- ...deployment ,
189- chart : template ( tmpl ) ,
190- } ) ) ) ) ,
191- rx . toArray ( ) ,
192- ) ;
159+ /* Take a Map of Deployment entries. Look up the chart
160+ * templates. Returns an array of individual charts which need
161+ * to be deployed. */
162+ /* XXX This is now all sync and could be done with imm rather
163+ * than rx. */
164+ const lookup = ( { deployments, templates } ) => rxx . rx (
165+ rx . from ( deployments ) ,
166+ // XXX - The support for the charts key is deprecated
167+ // and will be removed in a future version. This is here
168+ // for backward compatibility. New deployments should
169+ // use the chart key instead.
170+ rx . mergeMap ( ( [ uuid , spec ] ) => rxx . rx (
171+ spec . chart ? rx . of ( spec . chart ) : rx . from ( spec . charts ?? [ ] ) ,
172+ rx . map ( chart => ( { uuid, spec, chart } ) ) ) ) ,
173+ rx . map ( ( { uuid, spec, chart } ) => ( {
174+ uuid, spec,
175+ chart : templates . get ( chart ) ,
176+ } ) ) ,
177+ rx . filter ( d => d . chart ) ,
178+ rx . toArray ( ) ) ;
179+
180+ /* Track deployments targetting this cluster */
181+ const deployments = cdb . search_app ( Deployments , { cluster : this . cluster } ) ;
182+
183+ /* Track and compile Helm Chart templates */
184+ const templates = rxx . rx (
185+ cdb . search_app ( HelmChart ) ,
186+ rx . map ( charts => charts . map ( compile_template ) ) ) ;
193187
194- // Watch for deployments targeting this cluster
195188 return rxx . rx (
196- cdb . search_app ( Deployments , { cluster : this . cluster } ) ,
197- rx . tap ( ds => this . log ( "DEPLOYMENTS: %o" , ds . toJS ( ) ) ) ,
189+ rx . combineLatest ( { templates, deployments } ) ,
198190 rx . switchMap ( lookup ) ) ;
199191 }
200192
201193 _init_manifests ( config , deployments ) {
202194 return rx . combineLatest ( { config, deployments } ) . pipe (
203- rx . tap ( opts => this . log ( "Reconcile needed: %o" , opts ) ) ,
195+ // rx.tap(opts => this.log("Reconcile needed: %o", opts)),
204196 rx . map ( opts => ( {
205197 resources : opts . config . resources ,
206198 manifests : this . create_manifests ( opts ) ,
207199 } ) ) ,
208- rx . tap ( o => this . log ( "Resources: %o, Manifests: %o" ,
209- o . resources . toJS ( ) , o . manifests . toJS ( ) ) ) ,
200+ // rx.tap(o => this.log("Resources: %o, Manifests: %o",
201+ // o.resources.toJS(), o.manifests.toJS())),
210202 rx . tap ( { error : e => this . log ( "Error: %s" , e ) } ) ,
211203 rx . retry ( { delay : 5000 } ) ,
212204 ) ;
@@ -219,7 +211,7 @@ export class Deployments {
219211 create_manifests ( { config, deployments } ) {
220212 return imm . List ( deployments )
221213 . flatMap ( deployment => {
222- const { uuid, spec, tmpl } = deployment ;
214+ const { uuid, spec } = deployment ;
223215 const chart = deployment . chart ( {
224216 uuid,
225217 name : spec . name ,
0 commit comments