Skip to content

Commit

Permalink
feat: Handle failure to load cluster specs gracefully in support-bund…
Browse files Browse the repository at this point in the history
…le command (#1660)

* feat: Handle failure to load cluster specs gracefully in support-bundle command

In some scenarios, we don't want to fail when unable to load specs from
the cluster. This is particularly useful when:

- A host support bundle is available on disk.
- There are specs defined in the cluster.
- The cluster is malfunctioning or inaccessible.
- We still need to generate a support bundle using only the host specs.
- This change allows users to generate a support bundle even if the
  embedded cluster is not functioning properly, making the process more
  resilient.

The primary motivation is to introduce a new command:

```
./embedded-cluster support-bundle
```

When executed, this command attempts to collect both host and cluster
specs. However, if the embedded cluster is broken or unavailable, the
command will skip loading the cluster specs and focus on the host,
ensuring that users can still gather critical information without
interruption.

* chore: use fmt printf instead of klog

* Update internal/specs/specs.go

Co-authored-by: Evans Mungai <evans@replicated.com>

---------

Co-authored-by: Evans Mungai <evans@replicated.com>
  • Loading branch information
ricardomaraschini and banjoh authored Oct 23, 2024
1 parent af8f682 commit 7ed2f4b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/specs/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
if vp.GetBool("load-cluster-specs") {
clusterKinds, err := LoadFromCluster(ctx, client, vp.GetStringSlice("selector"), vp.GetString("namespace"))
if err != nil {
return nil, types.NewExitCodeError(constants.EXIT_CODE_SPEC_ISSUES, err)
if kinds.IsEmpty() {
return nil, types.NewExitCodeError(constants.EXIT_CODE_SPEC_ISSUES, err)
}
// TODO: Consider colour coding and graceful failures when loading specs
fmt.Printf("failed to load specs from the cluster: %v\n", err)
} else {
kinds.Add(clusterKinds)
}

kinds.Add(clusterKinds)
}

return kinds, nil
Expand Down

0 comments on commit 7ed2f4b

Please sign in to comment.