Skip to content

Commit

Permalink
Merge pull request #1189 from prafull01/unserved
Browse files Browse the repository at this point in the history
🐛 Fix the unserved version CRD install timeout in envtest
  • Loading branch information
k8s-ci-robot committed Oct 13, 2020
2 parents bd97e08 + e4ca925 commit f52b618
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 5 deletions.
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 {
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: []

0 comments on commit f52b618

Please sign in to comment.