Skip to content

Commit fffd220

Browse files
Merge pull request #2249 from benluddy/remove-crd-v1beta1-tests
Remove test dependencies on the v1beta1 CRD API.
2 parents c8d1af7 + b7febc1 commit fffd220

28 files changed

+694
-627
lines changed

Diff for: .github/workflows/e2e-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12+
- uses: actions/setup-go@v2
13+
with:
14+
go-version: '~1.16'
1215
- run: make e2e-local NODES=2 JUNIT_DIRECTORY=./artifacts/
1316
- name: Archive Test Artifacts # test results, failed or not, are always uploaded.
1417
if: ${{ always() }}

Diff for: test/e2e/bundle_e2e_test.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package e2e
22

33
import (
44
"context"
5+
_ "embed"
56
"encoding/json"
67

78
"github.com/ghodss/yaml"
8-
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
9+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
910
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1011
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1112

@@ -19,9 +20,11 @@ import (
1920
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
2021
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2122
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
22-
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/testdata/vpa"
2323
)
2424

25+
//go:embed testdata/vpa/crd.yaml
26+
var vpaCRDRaw []byte
27+
2528
var _ = Describe("Installing bundles with new object types", func() {
2629
var (
2730
kubeClient operatorclient.ClientInterface
@@ -55,10 +58,8 @@ var _ = Describe("Installing bundles with new object types", func() {
5558
)
5659

5760
// create VPA CRD on cluster
58-
y, err := vpa.Asset("test/e2e/testdata/vpa/crd.yaml")
59-
Expect(err).ToNot(HaveOccurred(), "could not read vpa bindata")
60-
61-
data, err := yaml.YAMLToJSON(y)
61+
Expect(vpaCRDRaw).ToNot(BeEmpty(), "could not read vpa bindata")
62+
data, err := yaml.YAMLToJSON(vpaCRDRaw)
6263
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to json")
6364

6465
err = json.Unmarshal(data, &vpaCRD)
@@ -76,7 +77,7 @@ var _ = Describe("Installing bundles with new object types", func() {
7677

7778
// ensure vpa crd is established and accepted on the cluster before continuing
7879
Eventually(func() (bool, error) {
79-
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), vpaCRD.GetName(), metav1.GetOptions{})
80+
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), vpaCRD.GetName(), metav1.GetOptions{})
8081
if err != nil {
8182
return false, err
8283
}
@@ -167,19 +168,19 @@ var _ = Describe("Installing bundles with new object types", func() {
167168
})
168169
})
169170

170-
func crdReady(status *apiextensionsv1beta1.CustomResourceDefinitionStatus) bool {
171+
func crdReady(status *apiextensionsv1.CustomResourceDefinitionStatus) bool {
171172
if status == nil {
172173
return false
173174
}
174175
established, namesAccepted := false, false
175176
for _, cdt := range status.Conditions {
176177
switch cdt.Type {
177-
case apiextensionsv1beta1.Established:
178-
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
178+
case apiextensionsv1.Established:
179+
if cdt.Status == apiextensionsv1.ConditionTrue {
179180
established = true
180181
}
181-
case apiextensionsv1beta1.NamesAccepted:
182-
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
182+
case apiextensionsv1.NamesAccepted:
183+
if cdt.Status == apiextensionsv1.ConditionTrue {
183184
namesAccepted = true
184185
}
185186
}

Diff for: test/e2e/crd_e2e_test.go

+47-98
Original file line numberDiff line numberDiff line change
@@ -14,95 +14,13 @@ import (
1414

1515
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1616
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
17-
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1817
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1918
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2019
)
2120

2221
var _ = Describe("CRD Versions", func() {
2322
AfterEach(func() { TearDown(testNamespace) }, float64(30))
2423

25-
It("creates v1beta1 crds with a v1beta1 schema successfully", func() {
26-
By("This test proves that OLM is able to handle v1beta1 CRDs successfully. Creating v1 CRDs has more " +
27-
"restrictions around the schema. v1beta1 validation schemas are not necessarily valid in v1. " +
28-
"OLM should support both v1beta1 and v1 CRDs")
29-
c := newKubeClient()
30-
crc := newCRClient()
31-
32-
mainPackageName := genName("nginx-update2-")
33-
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
34-
stableChannel := "stable"
35-
36-
crdPlural := genName("ins-v1beta1-")
37-
crdName := crdPlural + ".cluster.com"
38-
mainCRD := apiextensions.CustomResourceDefinition{
39-
ObjectMeta: metav1.ObjectMeta{
40-
Name: crdName,
41-
},
42-
Spec: apiextensions.CustomResourceDefinitionSpec{
43-
Group: "cluster.com",
44-
Versions: []apiextensions.CustomResourceDefinitionVersion{
45-
{
46-
Name: "v1alpha1",
47-
Served: true,
48-
Storage: true,
49-
},
50-
},
51-
Names: apiextensions.CustomResourceDefinitionNames{
52-
Plural: crdPlural,
53-
Singular: crdPlural,
54-
Kind: crdPlural,
55-
ListKind: "list" + crdPlural,
56-
},
57-
Scope: "Namespaced",
58-
// this validation is not a valid v1 structural schema because the "type: object" field is missing
59-
Validation: &apiextensions.CustomResourceValidation{
60-
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
61-
Description: "my crd schema",
62-
},
63-
},
64-
},
65-
}
66-
67-
mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, nil)
68-
mainCatalogName := genName("mock-ocs-main-update2-")
69-
mainManifests := []registry.PackageManifest{
70-
{
71-
PackageName: mainPackageName,
72-
Channels: []registry.PackageChannel{
73-
{Name: stableChannel, CurrentCSVName: mainPackageStable},
74-
},
75-
DefaultChannelName: stableChannel,
76-
},
77-
}
78-
79-
// Create the catalog sources
80-
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{mainCRD}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
81-
defer cleanupMainCatalogSource()
82-
83-
// Attempt to get the catalog source before creating install plan
84-
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
85-
Expect(err).ToNot(HaveOccurred())
86-
87-
subscriptionName := genName("sub-nginx-update2-")
88-
subscriptionCleanup := createSubscriptionForCatalog(crc, testNamespace, subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
89-
defer subscriptionCleanup()
90-
91-
subscription, err := fetchSubscription(crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
92-
Expect(err).ToNot(HaveOccurred())
93-
Expect(subscription).ToNot(Equal(nil))
94-
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
95-
Expect(mainCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
96-
97-
installPlanName := subscription.Status.InstallPlanRef.Name
98-
99-
// Wait for InstallPlan to be status: Complete before checking resource presence
100-
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
101-
Expect(err).ToNot(HaveOccurred())
102-
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
103-
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
104-
})
105-
10624
It("creates v1 CRDs with a v1 schema successfully", func() {
10725
By("v1 crds with a valid openapiv3 schema should be created successfully by OLM")
10826
c := newKubeClient()
@@ -112,13 +30,14 @@ var _ = Describe("CRD Versions", func() {
11230
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
11331
stableChannel := "stable"
11432

115-
crdPlural := genName("ins-v1beta1-")
33+
crdPlural := genName("ins-")
11634
crdName := crdPlural + ".cluster.com"
11735
v1crd := apiextensionsv1.CustomResourceDefinition{
11836
ObjectMeta: metav1.ObjectMeta{
11937
Name: crdName,
12038
},
12139
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
40+
Scope: apiextensionsv1.NamespaceScoped,
12241
Group: "cluster.com",
12342
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
12443
{
@@ -185,7 +104,7 @@ var _ = Describe("CRD Versions", func() {
185104
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
186105
stableChannel := "stable"
187106

188-
crdPlural := genName("ins-v1beta1-")
107+
crdPlural := genName("ins-")
189108
crdName := crdPlural + ".cluster.com"
190109
oldCRD := apiextensions.CustomResourceDefinition{
191110
ObjectMeta: metav1.ObjectMeta{
@@ -209,6 +128,12 @@ var _ = Describe("CRD Versions", func() {
209128
Name: "v2alpha1",
210129
Served: true,
211130
Storage: false,
131+
Schema: &apiextensions.CustomResourceValidation{
132+
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
133+
Type: "object",
134+
Description: "my crd schema",
135+
},
136+
},
212137
},
213138
},
214139
Names: apiextensions.CustomResourceDefinitionNames{
@@ -217,7 +142,7 @@ var _ = Describe("CRD Versions", func() {
217142
Kind: crdPlural,
218143
ListKind: "list" + crdPlural,
219144
},
220-
Scope: "Namespaced",
145+
Scope: apiextensions.NamespaceScoped,
221146
},
222147
}
223148

@@ -245,6 +170,12 @@ var _ = Describe("CRD Versions", func() {
245170
Name: "v2alpha2",
246171
Served: true,
247172
Storage: false,
173+
Schema: &apiextensions.CustomResourceValidation{
174+
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
175+
Type: "object",
176+
Description: "my crd schema",
177+
},
178+
},
248179
},
249180
},
250181
Names: apiextensions.CustomResourceDefinitionNames{
@@ -253,6 +184,7 @@ var _ = Describe("CRD Versions", func() {
253184
Kind: crdPlural,
254185
ListKind: "list" + crdPlural,
255186
},
187+
Scope: apiextensions.NamespaceScoped,
256188
},
257189
}
258190

@@ -352,49 +284,60 @@ var _ = Describe("CRD Versions", func() {
352284
crdName := crdPlural + ".cluster.com"
353285
crdGroup := "cluster.com"
354286

355-
oldCRD := &apiextensionsv1beta1.CustomResourceDefinition{
287+
oldCRD := &apiextensionsv1.CustomResourceDefinition{
356288
ObjectMeta: metav1.ObjectMeta{
357289
Name: crdName,
358290
},
359-
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
291+
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
360292
Group: crdGroup,
361-
Versions: []apiextensionsv1beta1.CustomResourceDefinitionVersion{
293+
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
362294
{
363295
Name: "v1alpha1",
364296
Served: true,
365297
Storage: true,
298+
Schema: &apiextensionsv1.CustomResourceValidation{
299+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
300+
Type: "object",
301+
Description: "my crd schema",
302+
},
303+
},
366304
},
367305
},
368-
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
306+
Names: apiextensionsv1.CustomResourceDefinitionNames{
369307
Plural: crdPlural,
370308
Singular: crdPlural,
371309
Kind: crdPlural,
372310
ListKind: "list" + crdPlural,
373311
},
374-
Scope: "Namespaced",
312+
Scope: apiextensionsv1.NamespaceScoped,
375313
},
376314
}
377-
_, err := c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.TODO(), oldCRD, metav1.CreateOptions{})
315+
_, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), oldCRD, metav1.CreateOptions{})
378316
Expect(err).ToNot(HaveOccurred(), "error creating old CRD")
379317

380318
// wrap CRD update in a poll because of the object has been modified related errors
381319
Eventually(func() error {
382-
oldCRD, err = c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
320+
oldCRD, err = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
383321
if err != nil {
384322
return err
385323
}
386324
GinkgoT().Logf("old crd status stored versions: %#v", oldCRD.Status.StoredVersions)
387325

388-
// set v1alpha1 to no longer served
326+
// set v1alpha1 to no longer stored
389327
oldCRD.Spec.Versions[0].Storage = false
390328
// update CRD on-cluster with a new version
391-
oldCRD.Spec.Versions = append(oldCRD.Spec.Versions, apiextensionsv1beta1.CustomResourceDefinitionVersion{
329+
oldCRD.Spec.Versions = append(oldCRD.Spec.Versions, apiextensionsv1.CustomResourceDefinitionVersion{
392330
Name: "v1alpha2",
393331
Served: true,
394332
Storage: true,
333+
Schema: &apiextensionsv1.CustomResourceValidation{
334+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
335+
Type: "object",
336+
},
337+
},
395338
})
396339

397-
updatedCRD, err := c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Update(context.TODO(), oldCRD, metav1.UpdateOptions{})
340+
updatedCRD, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Update(context.TODO(), oldCRD, metav1.UpdateOptions{})
398341
if err != nil {
399342
return err
400343
}
@@ -414,6 +357,12 @@ var _ = Describe("CRD Versions", func() {
414357
Name: "v1alpha2",
415358
Served: true,
416359
Storage: true,
360+
Schema: &apiextensions.CustomResourceValidation{
361+
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
362+
Type: "object",
363+
Description: "my crd schema",
364+
},
365+
},
417366
},
418367
},
419368
Names: apiextensions.CustomResourceDefinitionNames{
@@ -422,7 +371,7 @@ var _ = Describe("CRD Versions", func() {
422371
Kind: crdPlural,
423372
ListKind: "list" + crdPlural,
424373
},
425-
Scope: "Namespaced",
374+
Scope: apiextensions.NamespaceScoped,
426375
},
427376
}
428377

@@ -471,10 +420,10 @@ var _ = Describe("CRD Versions", func() {
471420
))
472421

473422
// update CRD status to remove the v1alpha1 stored version
474-
newCRD, err := c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
423+
newCRD, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
475424
Expect(err).ToNot(HaveOccurred(), "error getting new CRD")
476425
newCRD.Status.StoredVersions = []string{"v1alpha2"}
477-
newCRD, err = c.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().UpdateStatus(context.TODO(), newCRD, metav1.UpdateOptions{})
426+
newCRD, err = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().UpdateStatus(context.TODO(), newCRD, metav1.UpdateOptions{})
478427
Expect(err).ToNot(HaveOccurred(), "error updating new CRD")
479428
GinkgoT().Logf("new crd status stored versions: %#v", newCRD.Status.StoredVersions) // only v1alpha2 should be in the status now
480429

0 commit comments

Comments
 (0)