mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
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:
@@ -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...)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user