Skip to content

Commit

Permalink
fix: [sc-116508] [Troubleshoot] support-bundle load-spec from URI fie…
Browse files Browse the repository at this point in the history
…ld logic is fragile (#1716)

do not load invalid URI
  • Loading branch information
nvanthao authored Jan 7, 2025
1 parent 4e10565 commit 7a00dbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
18 changes: 18 additions & 0 deletions cmd/troubleshoot/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7a00dbe

Please sign in to comment.