diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index 963dbac48..8ef25b7cb 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -20,6 +20,7 @@ import ( "github.com/replicatedhq/troubleshoot/internal/util" analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" + "github.com/replicatedhq/troubleshoot/pkg/collect" "github.com/replicatedhq/troubleshoot/pkg/constants" "github.com/replicatedhq/troubleshoot/pkg/convert" "github.com/replicatedhq/troubleshoot/pkg/httputil" @@ -301,6 +302,19 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) mainBundle.Spec.HostCollectors = append(mainBundle.Spec.HostCollectors, hc.Spec.Collectors...) } + // Ensure cluster info and cluster resources collectors are in the merged spec + // We need to add them here so when we --dry-run, these collectors are included + // supportbundle.runCollectors duplicates this bit. We'll need to refactor it out later + // when its clearer what other code depends that logic e.g KOTS + mainBundle.Spec.Collectors = collect.EnsureCollectorInList( + mainBundle.Spec.Collectors, + troubleshootv1beta2.Collect{ClusterInfo: &troubleshootv1beta2.ClusterInfo{}}, + ) + mainBundle.Spec.Collectors = collect.EnsureCollectorInList( + mainBundle.Spec.Collectors, + troubleshootv1beta2.Collect{ClusterResources: &troubleshootv1beta2.ClusterResources{}}, + ) + additionalRedactors := &troubleshootv1beta2.Redactor{ TypeMeta: metav1.TypeMeta{ APIVersion: "troubleshoot.sh/v1beta2", diff --git a/pkg/loader/loader_test.go b/pkg/loader/loader_test.go index 5ae629377..a1d12d287 100644 --- a/pkg/loader/loader_test.go +++ b/pkg/loader/loader_test.go @@ -579,3 +579,24 @@ spec: ignoreRBAC: true`) assert.Contains(t, string(y), "message: Cluster is up to date") } + +func TestLoadingEmptySpec(t *testing.T) { + s := testutils.GetTestFixture(t, "supportbundle/empty.yaml") + kinds, err := LoadSpecs(context.Background(), LoadOptions{RawSpec: s}) + require.NoError(t, err) + require.NotNil(t, kinds) + + assert.Equal(t, &TroubleshootKinds{ + SupportBundlesV1Beta2: []troubleshootv1beta2.SupportBundle{ + { + TypeMeta: metav1.TypeMeta{ + Kind: "SupportBundle", + APIVersion: "troubleshoot.sh/v1beta2", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "empty", + }, + }, + }, + }, kinds) +}