Skip to content

Commit 1544699

Browse files
authored
fix: Parse v1beta1 troubleshoot specs when using loader API (#1501)
1 parent c4237b6 commit 1544699

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const (
7979

8080
// Troubleshoot spec constants
8181
Troubleshootv1beta2Kind = "troubleshoot.sh/v1beta2"
82+
Troubleshootv1beta1Kind = "troubleshoot.replicated.com/v1beta1"
8283

8384
// TermUI Display Constants
8485
MESSAGE_TEXT_PADDING = 4

pkg/loader/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (l *specLoader) loadFromStrings(rawSpecs ...string) (*TroubleshootKinds, er
196196
default:
197197
return nil, types.NewExitCodeError(constants.EXIT_CODE_SPEC_ISSUES, errors.Errorf("%T type is not a Secret or ConfigMap", v))
198198
}
199-
} else if parsed.APIVersion == constants.Troubleshootv1beta2Kind {
199+
} else if parsed.APIVersion == constants.Troubleshootv1beta2Kind || parsed.APIVersion == constants.Troubleshootv1beta1Kind {
200200
// If it's not a configmap or secret, just append it to the splitdocs
201201
splitdocs = append(splitdocs, rawDoc)
202202
} else {

pkg/loader/loader_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,38 @@ func TestLoadingMultidocsWithTroubleshootSpecs(t *testing.T) {
371371
}, kinds.SupportBundlesV1Beta2)
372372
}
373373

374+
func TestLoadingV1Beta1CollectorSpec(t *testing.T) {
375+
kinds, err := LoadSpecs(context.Background(), LoadOptions{RawSpec: `kind: Collector
376+
apiVersion: troubleshoot.replicated.com/v1beta1
377+
metadata:
378+
name: collector-sample
379+
spec:
380+
collectors:
381+
- clusterInfo: {}
382+
`})
383+
require.NoError(t, err)
384+
require.NotNil(t, kinds)
385+
386+
assert.Equal(t, []troubleshootv1beta2.Collector{
387+
{
388+
TypeMeta: metav1.TypeMeta{
389+
Kind: "Collector",
390+
APIVersion: "troubleshoot.sh/v1beta2",
391+
},
392+
ObjectMeta: metav1.ObjectMeta{
393+
Name: "collector-sample",
394+
},
395+
Spec: troubleshootv1beta2.CollectorSpec{
396+
Collectors: []*troubleshootv1beta2.Collect{
397+
{
398+
ClusterInfo: &troubleshootv1beta2.ClusterInfo{},
399+
},
400+
},
401+
},
402+
},
403+
}, kinds.CollectorsV1Beta2)
404+
}
405+
374406
func TestLoadingConfigMapWithMultipleSpecs_PreflightSupportBundleAndRedactorDataKeys(t *testing.T) {
375407
s := testutils.GetTestFixture(t, "yamldocs/multidoc-spec-2.yaml")
376408
l := specLoader{}

0 commit comments

Comments
 (0)