Skip to content

Commit 2c4931d

Browse files
Merge pull request #352 from ecordell/support-v1-crds
Bug 1825512: Support v1 crds in manifests
2 parents 3b3305b + 2bbae29 commit 2c4931d

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

lib/resourceread/apiext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func init() {
2323

2424
// ReadCustomResourceDefinitionOrDie reads crd object from bytes as v1 or v1beta1. Panics on error.
2525
func ReadCustomResourceDefinitionOrDie(objBytes []byte) runtime.Object {
26-
requiredObj, err := runtime.Decode(apiExtensionsCodecs.UniversalDecoder(apiextv1beta1.SchemeGroupVersion), objBytes)
26+
requiredObj, err := runtime.Decode(apiExtensionsCodecs.UniversalDecoder(apiextv1beta1.SchemeGroupVersion, apiextv1.SchemeGroupVersion), objBytes)
2727
if err != nil {
2828
panic(err)
2929
}

lib/resourceread/apiext_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package resourceread
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestReadCustomResourceDefinitionOrDie(t *testing.T) {
8+
type args struct {
9+
objBytes []byte
10+
}
11+
tests := []struct {
12+
name string
13+
args args
14+
}{
15+
{
16+
name:"v1",
17+
args: args{
18+
objBytes: []byte(`
19+
apiVersion: apiextensions.k8s.io/v1
20+
kind: CustomResourceDefinition
21+
metadata:
22+
name: shoulds.parse.com
23+
spec:
24+
group: parse.com
25+
names:
26+
kind: ShouldParse
27+
listKind: ShouldParseList
28+
plural: shoulds
29+
singular: should
30+
scope: Namespaced
31+
versions:
32+
- name: v1alpha1
33+
schema:
34+
openAPIV3Schema:
35+
description: ShouldParse is a v1 CRD that should be parsed.
36+
type: object
37+
served: true
38+
storage: true
39+
subresources:
40+
status: {}
41+
`),
42+
},
43+
},
44+
{
45+
name:"v1beta1",
46+
args: args{
47+
objBytes: []byte(`
48+
apiVersion: apiextensions.k8s.io/v1beta1
49+
kind: CustomResourceDefinition
50+
metadata:
51+
name: alreadys.parse.com
52+
spec:
53+
group: parse.com
54+
names:
55+
kind: AlreadyParse
56+
listKind: AlreadyParseList
57+
plural: alreadys
58+
singular: already
59+
scope: Namespaced
60+
versions:
61+
- name: v1alpha1
62+
schema:
63+
openAPIV3Schema:
64+
description: AlreadyParse is a v1beta1 CRD that should be parsed.
65+
type: object
66+
served: true
67+
storage: true
68+
subresources:
69+
status: {}
70+
`),
71+
},
72+
},
73+
}
74+
for _, tt := range tests {
75+
t.Run(tt.name, func(t *testing.T) {
76+
defer func() {
77+
if r := recover(); r != nil {
78+
t.Error(r)
79+
t.Fail()
80+
}
81+
}()
82+
_ = ReadCustomResourceDefinitionOrDie(tt.args.objBytes)
83+
})
84+
}
85+
}

0 commit comments

Comments
 (0)