@@ -337,6 +337,10 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
337
337
rt .Spec .IngressHost = opts .IngressHost
338
338
rt .Spec .Repo = opts .InsCloneOpts .Repo
339
339
340
+ var installationErr error
341
+
342
+ defer reportInstallationErrorToPlatform (ctx , opts .RuntimeName , & installationErr )
343
+
340
344
log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("Installing runtime '%s'" , opts .RuntimeName )
341
345
err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
342
346
AppSpecifier : rt .Spec .FullSpecifier (),
@@ -349,7 +353,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
349
353
},
350
354
})
351
355
if err != nil {
352
- return fmt .Errorf ("failed to bootstrap repository: %w" , err )
356
+ installationErr = fmt .Errorf ("failed to bootstrap repository: %w" , err )
357
+ return installationErr
353
358
}
354
359
355
360
err = apcmd .RunProjectCreate (ctx , & apcmd.ProjectCreateOptions {
@@ -360,25 +365,29 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
360
365
},
361
366
})
362
367
if err != nil {
363
- return fmt .Errorf ("failed to create project: %w" , err )
368
+ installationErr = fmt .Errorf ("failed to create project: %w" , err )
369
+ return installationErr
364
370
}
365
371
366
372
// persists codefresh-cm, this must be created before events-reporter eventsource
367
373
// otherwise it will not start and no events will get to the platform.
368
374
if err = persistRuntime (ctx , opts .InsCloneOpts , rt , opts .CommonConfig ); err != nil {
369
- return fmt .Errorf ("failed to create codefresh-cm: %w" , err )
375
+ installationErr = fmt .Errorf ("failed to create codefresh-cm: %w" , err )
376
+ return installationErr
370
377
}
371
378
372
379
for _ , component := range rt .Spec .Components {
373
380
log .G (ctx ).Infof ("Creating component '%s'" , component .Name )
374
381
if err = component .CreateApp (ctx , opts .KubeFactory , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFComponentType , "" , "" ); err != nil {
375
- return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
382
+ installationErr = fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
383
+ return installationErr
376
384
}
377
385
}
378
386
379
387
err = installComponents (ctx , opts , rt )
380
388
if err != nil {
381
- return err
389
+ installationErr = fmt .Errorf ("failed to install components: %s" , err )
390
+ return installationErr
382
391
}
383
392
384
393
if err = RunGitSourceCreate (ctx , & GitSourceCreateOptions {
@@ -388,7 +397,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
388
397
RuntimeName : opts .RuntimeName ,
389
398
CreateDemoResources : opts .SampleInstall ,
390
399
}); err != nil {
391
- return fmt .Errorf ("failed to create `%s`: %w" , store .Get ().GitSourceName , err )
400
+ installationErr = fmt .Errorf ("failed to create `%s`: %w" , store .Get ().GitSourceName , err )
401
+ return installationErr
392
402
}
393
403
394
404
mpCloneOpts := & git.CloneOptions {
@@ -405,22 +415,44 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
405
415
CreateDemoResources : false ,
406
416
Include : "**/workflowTemplate.yaml" ,
407
417
}); err != nil {
408
- return fmt .Errorf ("failed to create `%s`: %w" , store .Get ().MarketplaceGitSourceName , err )
418
+ installationErr = fmt .Errorf ("failed to create `%s`: %w" , store .Get ().MarketplaceGitSourceName , err )
419
+ return installationErr
409
420
}
410
421
411
422
var wg sync.WaitGroup
412
423
413
424
wg .Add (1 )
414
425
err = intervalCheckIsRuntimePersisted (ctx , opts .RuntimeName , & wg )
415
426
if err != nil {
416
- return fmt .Errorf ("failed to complete installation: %w" , err )
427
+ installationErr = fmt .Errorf ("failed to complete installation: %w" , err )
428
+ return installationErr
417
429
}
418
430
wg .Wait ()
419
431
420
432
log .G (ctx ).Infof ("Done installing runtime '%s'" , opts .RuntimeName )
433
+
421
434
return nil
422
435
}
423
436
437
+ func reportInstallationErrorToPlatform (ctx context.Context , runtime string , err * error ) {
438
+ if * err == nil {
439
+ return
440
+ }
441
+
442
+ installationError := & model.HealthErrorInput {
443
+ Level : model .ErrorLevelsError ,
444
+ Message : (* err ).Error (),
445
+ }
446
+ _ , err1 := cfConfig .NewClient ().V2 ().Runtime ().ReportErrors (ctx , & model.ReportRuntimeErrorsArgs {
447
+ Runtime : runtime ,
448
+ Errors : []* model.HealthErrorInput {installationError },
449
+ })
450
+
451
+ if err1 != nil {
452
+ log .G (ctx ).Error ("failed to report installation errors of runtime: %s. Error: %s" , runtime , err1 )
453
+ }
454
+ }
455
+
424
456
func installComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
425
457
var err error
426
458
if opts .IngressHost != "" {
@@ -515,7 +547,7 @@ func checkExistingRuntimes(ctx context.Context, runtime string) error {
515
547
}
516
548
517
549
func intervalCheckIsRuntimePersisted (ctx context.Context , runtimeName string , wg * sync.WaitGroup ) error {
518
- maxRetries := 180 // up to 30 min
550
+ maxRetries := 180 // up to 30 min
519
551
longerThanUsualCount := 30 // after 5 min
520
552
waitMsg := "Waiting for the runtime installation to complete"
521
553
longetThanUsualMsg := waitMsg + " (this is taking longer than usual, you might need to check your cluster for errors)"
0 commit comments