@@ -221,18 +221,30 @@ func (d *deployer) deployComponents(ctx context.Context, pkgLayout *layout.Packa
221
221
}
222
222
223
223
if deployErr != nil {
224
- onFailure ()
225
- deployedComponents [idx ].Status = state .ComponentStatusFailed
226
- if d .isConnectedToCluster () {
227
- if _ , err := d .c .RecordPackageDeployment (ctx , pkgLayout .Pkg , deployedComponents , packageGeneration , state .WithPackageNamespaceOverride (opts .NamespaceOverride )); err != nil {
228
- l .Debug ("unable to record package deployment" , "component" , component .Name , "error" , err .Error ())
224
+ cleanup := func (ctx context.Context ) {
225
+ onFailure ()
226
+ l .Debug ("component deployment failed" , "component" , component .Name , "error" , deployErr .Error ())
227
+ deployedComponents [idx ].Status = state .ComponentStatusFailed
228
+ deployedComponents [idx ].InstalledCharts = state .MergeInstalledChartsForComponent (deployedComponents [idx ].InstalledCharts , charts , true )
229
+ if d .isConnectedToCluster () {
230
+ if _ , err := d .c .RecordPackageDeployment (ctx , pkgLayout .Pkg , deployedComponents , packageGeneration , state .WithPackageNamespaceOverride (opts .NamespaceOverride )); err != nil {
231
+ l .Debug ("unable to record package deployment" , "component" , component .Name , "error" , err .Error ())
232
+ }
229
233
}
230
234
}
231
- return nil , fmt .Errorf ("unable to deploy component %q: %w" , component .Name , deployErr )
235
+ select {
236
+ case <- ctx .Done ():
237
+ // Use background context here in order to ensure the cleanup logic can run when the context is cancelled
238
+ cleanup (context .Background ())
239
+ return nil , fmt .Errorf ("context cancelled while deploying component %q: %w" , component .Name , deployErr )
240
+ default :
241
+ cleanup (ctx )
242
+ return nil , fmt .Errorf ("unable to deploy component %q: %w" , component .Name , deployErr )
243
+ }
232
244
}
233
245
234
246
// Update the package secret to indicate that we successfully deployed this component
235
- deployedComponents [idx ].InstalledCharts = charts
247
+ deployedComponents [idx ].InstalledCharts = state . MergeInstalledChartsForComponent ( deployedComponents [ idx ]. InstalledCharts , charts , false )
236
248
deployedComponents [idx ].Status = state .ComponentStatusSucceeded
237
249
if d .isConnectedToCluster () {
238
250
if _ , err := d .c .RecordPackageDeployment (ctx , pkgLayout .Pkg , deployedComponents , packageGeneration , state .WithPackageNamespaceOverride (opts .NamespaceOverride )); err != nil {
@@ -421,35 +433,35 @@ func (d *deployer) deployComponent(ctx context.Context, pkgLayout *layout.Packag
421
433
charts := []state.InstalledChart {}
422
434
if hasCharts {
423
435
helmCharts , err := d .installCharts (ctx , pkgLayout , component , opts )
436
+ charts = append (charts , helmCharts ... )
424
437
if err != nil {
425
- return nil , err
438
+ return charts , err
426
439
}
427
- charts = append (charts , helmCharts ... )
428
440
}
429
441
430
442
if hasManifests {
431
443
chartsFromManifests , err := d .installManifests (ctx , pkgLayout , component , opts )
444
+ charts = append (charts , chartsFromManifests ... )
432
445
if err != nil {
433
- return nil , err
446
+ return charts , err
434
447
}
435
- charts = append (charts , chartsFromManifests ... )
436
448
}
437
449
438
450
if err := actions .Run (ctx , cwd , onDeploy .Defaults , onDeploy .After , d .vc ); err != nil {
439
- return nil , fmt .Errorf ("unable to run component after action: %w" , err )
451
+ return charts , fmt .Errorf ("unable to run component after action: %w" , err )
440
452
}
441
453
442
454
if len (component .HealthChecks ) > 0 {
443
455
healthCheckContext , cancel := context .WithTimeout (ctx , opts .Timeout )
444
456
defer cancel ()
445
457
l .Info ("running health checks" )
446
458
if err := healthchecks .Run (healthCheckContext , d .c .Watcher , component .HealthChecks ); err != nil {
447
- return nil , fmt .Errorf ("health checks failed: %w" , err )
459
+ return charts , fmt .Errorf ("health checks failed: %w" , err )
448
460
}
449
461
}
450
462
451
463
if err := g .Wait (); err != nil {
452
- return nil , err
464
+ return charts , err
453
465
}
454
466
l .Debug ("done deploying component" , "name" , component .Name , "duration" , time .Since (start ))
455
467
return charts , nil
@@ -485,15 +497,15 @@ func (d *deployer) installCharts(ctx context.Context, pkgLayout *layout.PackageL
485
497
for idx := range chart .ValuesFiles {
486
498
valueFilePath := helm .StandardValuesName (valuesDir , chart , idx )
487
499
if err := d .vc .ReplaceTextTemplate (valueFilePath ); err != nil {
488
- return nil , err
500
+ return installedCharts , err
489
501
}
490
502
}
491
503
492
504
// Create a Helm values overrides map from set Zarf `variables` and DeployOpts library inputs
493
505
// Values overrides are to be applied in order of Helm Chart Defaults -> Zarf `valuesFiles` -> Zarf `variables` -> DeployOpts overrides
494
506
valuesOverrides , err := generateValuesOverrides (chart , component .Name , d .vc , opts .ValuesOverridesMap )
495
507
if err != nil {
496
- return nil , err
508
+ return installedCharts , err
497
509
}
498
510
499
511
helmOpts := helm.InstallUpgradeOptions {
@@ -507,14 +519,15 @@ func (d *deployer) installCharts(ctx context.Context, pkgLayout *layout.PackageL
507
519
}
508
520
helmChart , values , err := helm .LoadChartData (chart , chartDir , valuesDir , valuesOverrides )
509
521
if err != nil {
510
- return nil , fmt .Errorf ("failed to load chart data: %w" , err )
522
+ return installedCharts , fmt .Errorf ("failed to load chart data: %w" , err )
511
523
}
512
524
513
525
connectStrings , installedChartName , err := helm .InstallOrUpgradeChart (ctx , chart , helmChart , values , helmOpts )
514
526
if err != nil {
515
- return nil , err
527
+ installedCharts = append (installedCharts , state.InstalledChart {Namespace : chart .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings , Status : state .ChartStatusFailed })
528
+ return installedCharts , err
516
529
}
517
- installedCharts = append (installedCharts , state.InstalledChart {Namespace : chart .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings })
530
+ installedCharts = append (installedCharts , state.InstalledChart {Namespace : chart .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings , Status : state . ChartStatusSucceeded })
518
531
}
519
532
520
533
return installedCharts , nil
@@ -540,7 +553,7 @@ func (d *deployer) installManifests(ctx context.Context, pkgLayout *layout.Packa
540
553
// The path is likely invalid because of how we compose OCI components, add an index suffix to the filename
541
554
manifest .Files [idx ] = fmt .Sprintf ("%s-%d.yaml" , manifest .Name , idx )
542
555
if helpers .InvalidPath (filepath .Join (manifestDir , manifest .Files [idx ])) {
543
- return nil , fmt .Errorf ("unable to find manifest file %s" , manifest .Files [idx ])
556
+ return installedCharts , fmt .Errorf ("unable to find manifest file %s" , manifest .Files [idx ])
544
557
}
545
558
}
546
559
}
@@ -558,7 +571,7 @@ func (d *deployer) installManifests(ctx context.Context, pkgLayout *layout.Packa
558
571
// Create a helmChart and helm cfg from a given Zarf Manifest.
559
572
chart , helmChart , err := helm .ChartFromZarfManifest (manifest , manifestDir , pkgLayout .Pkg .Metadata .Name , component .Name )
560
573
if err != nil {
561
- return nil , err
574
+ return installedCharts , err
562
575
}
563
576
helmOpts := helm.InstallUpgradeOptions {
564
577
AdoptExistingResources : opts .AdoptExistingResources ,
@@ -573,9 +586,10 @@ func (d *deployer) installManifests(ctx context.Context, pkgLayout *layout.Packa
573
586
// Install the chart.
574
587
connectStrings , installedChartName , err := helm .InstallOrUpgradeChart (ctx , chart , helmChart , nil , helmOpts )
575
588
if err != nil {
576
- return nil , err
589
+ installedCharts = append (installedCharts , state.InstalledChart {Namespace : manifest .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings , Status : state .ChartStatusFailed })
590
+ return installedCharts , err
577
591
}
578
- installedCharts = append (installedCharts , state.InstalledChart {Namespace : manifest .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings })
592
+ installedCharts = append (installedCharts , state.InstalledChart {Namespace : manifest .Namespace , ChartName : installedChartName , ConnectStrings : connectStrings , Status : state . ChartStatusSucceeded })
579
593
}
580
594
581
595
return installedCharts , nil
0 commit comments