Skip to content

Commit 0535d0a

Browse files
author
Phillip Wittrock
authored
Merge pull request #113 from pmorie/basic-config-crd-test
Add basic test for kubebuilder create config --crds
2 parents 044dc0f + 7960de2 commit 0535d0a

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

test.sh

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,53 @@ function generate_crd_resources {
118118
# Run the commands
119119
kubebuilder init repo --domain sample.kubernetes.io
120120
kubebuilder create resource --group insect --version v1beta1 --kind Bee
121+
122+
header_text "generating CRD definition"
123+
kubebuilder create config --crds --output crd.yaml
124+
125+
# Test for the expected generated CRD definition
126+
#
127+
# TODO: this is awkwardly inserted after the first resource created in this
128+
# test because the output order seems nondeterministic and it's preferable to
129+
# avoid introducing a new dependency like yq or complex parsing logic
130+
cat << EOF > expected.yaml
131+
apiVersion: apiextensions.k8s.io/v1beta1
132+
kind: CustomResourceDefinition
133+
metadata:
134+
creationTimestamp: null
135+
labels:
136+
api: ""
137+
kubebuilder.k8s.io: unknown
138+
name: bees.insect.sample.kubernetes.io
139+
spec:
140+
group: insect.sample.kubernetes.io
141+
names:
142+
kind: Bee
143+
plural: bees
144+
scope: Namespaced
145+
validation:
146+
openAPIV3Schema:
147+
properties:
148+
apiVersion:
149+
type: string
150+
kind:
151+
type: string
152+
metadata:
153+
type: object
154+
spec:
155+
type: object
156+
status:
157+
type: object
158+
type: object
159+
version: v1beta1
160+
status:
161+
acceptedNames:
162+
kind: ""
163+
plural: ""
164+
conditions: null
165+
EOF
166+
diff crd.yaml expected.yaml
167+
121168
kubebuilder create resource --group insect --version v1beta1 --kind Wasp
122169
}
123170

@@ -137,7 +184,7 @@ fetch_tools
137184
build_kb
138185
prepare_vendor_deps
139186
prepare_testdir_under_gopath
187+
140188
generate_crd_resources
141189
test_generated_controller
142-
143190
exit $rc

0 commit comments

Comments
 (0)