Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix the unserved version CRD install timeout in envtest #1189

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,17 @@ func WaitForCRDs(config *rest.Config, crds []client.Object, options CRDInstallOp
if err != nil {
return err
}
if crdVersion != "" {
gvs = append(gvs, schema.GroupVersion{Group: crdGroup, Version: crdVersion})
}

versions, _, err := unstructured.NestedSlice(crd.Object, "spec", "versions")
versions, found, err := unstructured.NestedSlice(crd.Object, "spec", "versions")
if err != nil {
return err
}

// gvs should be added here only if single version is found. If multiple version is found we will add those version
// based on the version is served or not.
if crdVersion != "" && !found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: (don't consider this blocking, but if for some reason you have to do another push, please fix): make found more descriptive, since it lasts more than a line. For example, isMultiVersion

gvs = append(gvs, schema.GroupVersion{Group: crdGroup, Version: crdVersion})
}

for _, version := range versions {
versionMap, ok := version.(map[string]interface{})
if !ok {
Expand Down
38 changes: 38 additions & 0 deletions pkg/envtest/envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ var _ = Describe("Test", func() {
}, teardownTimeoutSeconds)

Describe("InstallCRDs", func() {
It("should install the unserved CRDs into the cluster", func() {
crds, err = InstallCRDs(env.Config, CRDInstallOptions{
Paths: []string{filepath.Join(".", "testdata", "crds", "examplecrd_unserved.yaml")},
})
Expect(err).NotTo(HaveOccurred())

// Expect to find the CRDs

crdv1 := &apiextensionsv1.CustomResourceDefinition{}
err = c.Get(context.TODO(), types.NamespacedName{Name: "frigates.ship.example.com"}, crdv1)
Expect(err).NotTo(HaveOccurred())
Expect(crdv1.Spec.Names.Kind).To(Equal("Frigate"))

err = WaitForCRDs(env.Config, []client.Object{
&v1beta1.CustomResourceDefinition{
Spec: v1beta1.CustomResourceDefinitionSpec{
Group: "ship.example.com",
Names: v1beta1.CustomResourceDefinitionNames{
Plural: "frigates",
},
Versions: []v1beta1.CustomResourceDefinitionVersion{
{
Name: "v1",
Storage: true,
Served: false,
},
{
Name: "v1beta1",
Storage: false,
Served: false,
},
}},
},
},
CRDInstallOptions{MaxTime: 50 * time.Millisecond, PollInterval: 15 * time.Millisecond},
)
Expect(err).NotTo(HaveOccurred())
})
It("should install the CRDs into the cluster using directory", func(done Done) {
crds, err = InstallCRDs(env.Config, CRDInstallOptions{
Paths: []string{validDirectory},
Expand Down
61 changes: 61 additions & 0 deletions pkg/envtest/testdata/crds/examplecrd_unserved.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: frigates.ship.example.com
spec:
group: ship.example.com
names:
kind: Frigate
listKind: FrigateList
plural: frigates
singular: frigate
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: Frigate is the Schema for the frigates API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: FrigateSpec defines the desired state of Frigate
properties:
foo:
description: Foo is an example field of Frigate. Edit Frigate_types.go
to remove/update
type: string
type: object
status:
description: FrigateStatus defines the observed state of Frigate
type: object
type: object
version: v1
versions:
- name: v1
served: false
storage: true
- name: v1beta1
served: false
storage: false
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []