Skip to content

Commit d83f970

Browse files
CR-5968-failure-report (#149)
* report errors * report installation errors to platform * wip * bump version * go mod tidy * improvement * removed unused func * error fix * error fix
1 parent 68b7901 commit d83f970

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.139
1+
VERSION=v0.0.140
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
424456
func 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

517549
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
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)"

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.139/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.140/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.139/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/140/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.35.1
13+
github.com/codefresh-io/go-sdk v0.35.4
1414
github.com/fatih/color v1.12.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w
265265
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
266266
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
267267
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
268-
github.com/codefresh-io/go-sdk v0.35.1 h1:4gLZh08WcNpH2MtFrXqy1kFhtbom5O8aKZhMCrU4VS8=
269-
github.com/codefresh-io/go-sdk v0.35.1/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
268+
github.com/codefresh-io/go-sdk v0.35.4 h1:7j9Jk8tCaxERXVIxBc5yHdMgSC9uvgxlNXGT7HP/smM=
269+
github.com/codefresh-io/go-sdk v0.35.4/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
270270
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
271271
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
272272
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.139
8+
version: 0.0.140
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)