Skip to content

Commit

Permalink
Add default collectors when parsing support bundle specs
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 25, 2023
1 parent 0fbca57 commit 4390e14
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 4390e14

Please sign in to comment.