diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index 335f3320f..7ca4d3d09 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -273,6 +273,13 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh continue } + if len(k.SupportBundlesV1Beta2) == 0 { + // add back original spec + moreKinds.SupportBundlesV1Beta2 = append(moreKinds.SupportBundlesV1Beta2, s) + klog.Warningf("no support bundle spec found in URI: %s", s.Spec.Uri) + continue + } + // finally append the uri spec moreKinds.SupportBundlesV1Beta2 = append(moreKinds.SupportBundlesV1Beta2, k.SupportBundlesV1Beta2...) diff --git a/cmd/troubleshoot/cli/run_test.go b/cmd/troubleshoot/cli/run_test.go index 71ac2b4b3..1ae01620a 100644 --- a/cmd/troubleshoot/cli/run_test.go +++ b/cmd/troubleshoot/cli/run_test.go @@ -417,3 +417,21 @@ spec: assert.NotNil(t, sb.Spec.Collectors[1].ConfigMap) // come from the original spec assert.Nil(t, sb.Spec.Collectors[1].Logs) // come from the URI spec } + +func Test_loadInvalidURISpec(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(`invalid spec`)) + })) + defer srv.Close() + + // update URI spec with the server URL + orig := strings.ReplaceAll(templSpec(), "$MY_URI", srv.URL) + specFile := testutils.ServeFromFilePath(t, orig) + + ctx := context.Background() + client := testclient.NewSimpleClientset() + sb, _, err := loadSpecs(ctx, []string{specFile}, client) + require.NoError(t, err) + assert.Len(t, sb.Spec.Collectors, 3) // default + clusterInfo + clusterResources + assert.NotNil(t, sb.Spec.Collectors[0].ConfigMap) // come from the original spec +}