Skip to content

Commit

Permalink
Merge pull request #352 from ecordell/support-v1-crds
Browse files Browse the repository at this point in the history
Bug 1825512: Support v1 crds in manifests
  • Loading branch information
openshift-merge-robot committed Apr 18, 2020
2 parents 3b3305b + 2bbae29 commit 2c4931d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resourceread/apiext.go
Expand Up @@ -23,7 +23,7 @@ func init() {

// ReadCustomResourceDefinitionOrDie reads crd object from bytes as v1 or v1beta1. Panics on error.
func ReadCustomResourceDefinitionOrDie(objBytes []byte) runtime.Object {
requiredObj, err := runtime.Decode(apiExtensionsCodecs.UniversalDecoder(apiextv1beta1.SchemeGroupVersion), objBytes)
requiredObj, err := runtime.Decode(apiExtensionsCodecs.UniversalDecoder(apiextv1beta1.SchemeGroupVersion, apiextv1.SchemeGroupVersion), objBytes)
if err != nil {
panic(err)
}
Expand Down
85 changes: 85 additions & 0 deletions lib/resourceread/apiext_test.go
@@ -0,0 +1,85 @@
package resourceread

import (
"testing"
)

func TestReadCustomResourceDefinitionOrDie(t *testing.T) {
type args struct {
objBytes []byte
}
tests := []struct {
name string
args args
}{
{
name:"v1",
args: args{
objBytes: []byte(`
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: shoulds.parse.com
spec:
group: parse.com
names:
kind: ShouldParse
listKind: ShouldParseList
plural: shoulds
singular: should
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ShouldParse is a v1 CRD that should be parsed.
type: object
served: true
storage: true
subresources:
status: {}
`),
},
},
{
name:"v1beta1",
args: args{
objBytes: []byte(`
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: alreadys.parse.com
spec:
group: parse.com
names:
kind: AlreadyParse
listKind: AlreadyParseList
plural: alreadys
singular: already
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: AlreadyParse is a v1beta1 CRD that should be parsed.
type: object
served: true
storage: true
subresources:
status: {}
`),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Error(r)
t.Fail()
}
}()
_ = ReadCustomResourceDefinitionOrDie(tt.args.objBytes)
})
}
}

0 comments on commit 2c4931d

Please sign in to comment.