@@ -337,6 +337,10 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
337337 rt .Spec .IngressHost = opts .IngressHost
338338 rt .Spec .Repo = opts .InsCloneOpts .Repo
339339
340+ var installationErr error
341+
342+ defer reportInstallationErrorToPlatform (ctx , opts .RuntimeName , & installationErr )
343+
340344 log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("Installing runtime '%s'" , opts .RuntimeName )
341345 err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
342346 AppSpecifier : rt .Spec .FullSpecifier (),
@@ -349,7 +353,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
349353 },
350354 })
351355 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
353358 }
354359
355360 err = apcmd .RunProjectCreate (ctx , & apcmd.ProjectCreateOptions {
@@ -360,25 +365,29 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
360365 },
361366 })
362367 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
364370 }
365371
366372 // persists codefresh-cm, this must be created before events-reporter eventsource
367373 // otherwise it will not start and no events will get to the platform.
368374 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
370377 }
371378
372379 for _ , component := range rt .Spec .Components {
373380 log .G (ctx ).Infof ("Creating component '%s'" , component .Name )
374381 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
376384 }
377385 }
378386
379387 err = installComponents (ctx , opts , rt )
380388 if err != nil {
381- return err
389+ installationErr = fmt .Errorf ("failed to install components: %s" , err )
390+ return installationErr
382391 }
383392
384393 if err = RunGitSourceCreate (ctx , & GitSourceCreateOptions {
@@ -388,7 +397,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
388397 RuntimeName : opts .RuntimeName ,
389398 CreateDemoResources : opts .SampleInstall ,
390399 }); 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
392402 }
393403
394404 mpCloneOpts := & git.CloneOptions {
@@ -405,22 +415,44 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
405415 CreateDemoResources : false ,
406416 Include : "**/workflowTemplate.yaml" ,
407417 }); 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
409420 }
410421
411422 var wg sync.WaitGroup
412423
413424 wg .Add (1 )
414425 err = intervalCheckIsRuntimePersisted (ctx , opts .RuntimeName , & wg )
415426 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
417429 }
418430 wg .Wait ()
419431
420432 log .G (ctx ).Infof ("Done installing runtime '%s'" , opts .RuntimeName )
433+
421434 return nil
422435}
423436
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+
424456func installComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
425457 var err error
426458 if opts .IngressHost != "" {
@@ -515,7 +547,7 @@ func checkExistingRuntimes(ctx context.Context, runtime string) error {
515547}
516548
517549func intervalCheckIsRuntimePersisted (ctx context.Context , runtimeName string , wg * sync.WaitGroup ) error {
518- maxRetries := 180 // up to 30 min
550+ maxRetries := 180 // up to 30 min
519551 longerThanUsualCount := 30 // after 5 min
520552 waitMsg := "Waiting for the runtime installation to complete"
521553 longetThanUsualMsg := waitMsg + " (this is taking longer than usual, you might need to check your cluster for errors)"
0 commit comments