Skip to content

Commit 7a00dbe

Browse files
authored
fix: [sc-116508] [Troubleshoot] support-bundle load-spec from URI field logic is fragile (#1716)
do not load invalid URI
1 parent 4e10565 commit 7a00dbe

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

cmd/troubleshoot/cli/run.go

+7
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh
273273
continue
274274
}
275275

276+
if len(k.SupportBundlesV1Beta2) == 0 {
277+
// add back original spec
278+
moreKinds.SupportBundlesV1Beta2 = append(moreKinds.SupportBundlesV1Beta2, s)
279+
klog.Warningf("no support bundle spec found in URI: %s", s.Spec.Uri)
280+
continue
281+
}
282+
276283
// finally append the uri spec
277284
moreKinds.SupportBundlesV1Beta2 = append(moreKinds.SupportBundlesV1Beta2, k.SupportBundlesV1Beta2...)
278285

cmd/troubleshoot/cli/run_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,21 @@ spec:
417417
assert.NotNil(t, sb.Spec.Collectors[1].ConfigMap) // come from the original spec
418418
assert.Nil(t, sb.Spec.Collectors[1].Logs) // come from the URI spec
419419
}
420+
421+
func Test_loadInvalidURISpec(t *testing.T) {
422+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
423+
w.Write([]byte(`invalid spec`))
424+
}))
425+
defer srv.Close()
426+
427+
// update URI spec with the server URL
428+
orig := strings.ReplaceAll(templSpec(), "$MY_URI", srv.URL)
429+
specFile := testutils.ServeFromFilePath(t, orig)
430+
431+
ctx := context.Background()
432+
client := testclient.NewSimpleClientset()
433+
sb, _, err := loadSpecs(ctx, []string{specFile}, client)
434+
require.NoError(t, err)
435+
assert.Len(t, sb.Spec.Collectors, 3) // default + clusterInfo + clusterResources
436+
assert.NotNil(t, sb.Spec.Collectors[0].ConfigMap) // come from the original spec
437+
}

0 commit comments

Comments
 (0)