Skip to content

Commit

Permalink
gracefully handle unreachable URIs in loadSupportBundleSpecsFromURIs
Browse files Browse the repository at this point in the history
  • Loading branch information
diamonwiggins committed Oct 26, 2023
1 parent 66e070a commit d519b96
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/replicatedhq/troubleshoot/pkg/loader"
"github.com/replicatedhq/troubleshoot/pkg/supportbundle"
"github.com/replicatedhq/troubleshoot/pkg/types"
"github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2"

Check failure on line 31 in cmd/troubleshoot/cli/run.go

View workflow job for this annotation

GitHub Actions / ensure-schemas-are-generated

github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2 must be imported as k8s.io/klog/v2

Check failure on line 31 in cmd/troubleshoot/cli/run.go

View workflow job for this annotation

GitHub Actions / compile-supportbundle

github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2 must be imported as k8s.io/klog/v2

Check failure on line 31 in cmd/troubleshoot/cli/run.go

View workflow job for this annotation

GitHub Actions / goreleaser-test (amd64, windows)

github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2 must be imported as k8s.io/klog/v2

Check failure on line 31 in cmd/troubleshoot/cli/run.go

View workflow job for this annotation

GitHub Actions / test

github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2 must be imported as k8s.io/klog/v2

Check failure on line 31 in cmd/troubleshoot/cli/run.go

View workflow job for this annotation

GitHub Actions / test-integration

github.com/replicatedhq/vandoor/analyze-api/vendor/k8s.io/klog/v2 must be imported as k8s.io/klog/v2
"github.com/spf13/viper"
spin "github.com/tj/go-spin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -232,6 +233,7 @@ the %s Admin Console to begin analysis.`
return nil
}

// loadSupportBundleSpecsFromURIs loads support bundle specs from URIs
func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.TroubleshootKinds) (*loader.TroubleshootKinds, error) {
remoteRawSpecs := []string{}
for _, s := range kinds.SupportBundlesV1Beta2 {
Expand All @@ -241,12 +243,21 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh
// There is an opportunity to refactor this code in favour of the Loader APIs
rawSpec, err := supportbundle.LoadSupportBundleSpec(s.Spec.Uri)
if err != nil {
return nil, errors.Wrapf(err, "failed to load support bundle from URI %q", s.Spec.Uri)
// In the event a spec can't be loaded, we'll just skip it and print a warning
klog.Warningf("unable to load support bundle from URI: %q: %v", s.Spec.Uri, err)
continue
}
remoteRawSpecs = append(remoteRawSpecs, string(rawSpec))
}
}

// If we don't have any remote specs, return nil as opposed to erroring out
// This is to implicitly handle airgap scenarios
if len(remoteRawSpecs) == 0 {
klog.Warningf("unable to load any support bundles from URIs")
return nil, nil
}

return loader.LoadSpecs(ctx, loader.LoadOptions{
RawSpecs: remoteRawSpecs,
})
Expand Down

0 comments on commit d519b96

Please sign in to comment.