fix: [sc-116508] [Troubleshoot] support-bundle load-spec from URI field logic is fragile (#1716)

do not load invalid URI
This commit is contained in:
Gerard Nguyen
2025-01-08 09:03:32 +11:00
committed by GitHub
parent 4e105657d4
commit 7a00dbea05
2 changed files with 25 additions and 0 deletions

View File

@@ -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...)

View File

@@ -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
}