@@ -2,6 +2,12 @@ package e2e
22
33import (
44 "context"
5+ "encoding/json"
6+
7+ "github.com/ghodss/yaml"
8+ apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
9+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
10+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
511
612 . "github.com/onsi/ginkgo"
713 . "github.com/onsi/gomega"
@@ -14,6 +20,7 @@ import (
1420 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
1521 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1622 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
23+ "github.com/operator-framework/operator-lifecycle-manager/test/e2e/testdata/vpa"
1724)
1825
1926// FIXME: Reintegrate this test
@@ -35,21 +42,50 @@ var _ = PDescribe("Installing bundles with new object types", func() {
3542 })
3643
3744 When ("a bundle with a pdb, priorityclass, and VPA object is installed" , func () {
38- By ("including the VPA CRD in the CSV" )
3945 const (
4046 packageName = "busybox"
4147 channelName = "alpha"
4248 subName = "test-subscription"
4349 )
50+ var vpaCRD unstructured.Unstructured
4451
4552 BeforeEach (func () {
53+ By ("first installing the VPA CRD on cluster" )
4654 const (
4755 sourceName = "test-catalog"
4856 imageName = "quay.io/olmtest/single-bundle-index:pdb"
4957 )
5058
59+ // create VPA CRD on cluster
60+ y , err := vpa .Asset ("test/e2e/testdata/vpa/crd.yaml" )
61+ Expect (err ).ToNot (HaveOccurred (), "could not read vpa bindata" )
62+
63+ data , err := yaml .YAMLToJSON (y )
64+ Expect (err ).ToNot (HaveOccurred (), "could not convert vpa crd to json" )
65+
66+ err = json .Unmarshal (data , & vpaCRD )
67+ Expect (err ).ToNot (HaveOccurred (), "could not convert vpa crd to unstructured" )
68+
69+ Eventually (func () error {
70+ err := ctx .Ctx ().Client ().Create (context .TODO (), & vpaCRD )
71+ if err != nil {
72+ if ! k8serrors .IsAlreadyExists (err ) {
73+ return err
74+ }
75+ }
76+ return nil
77+ }).Should (Succeed ())
78+
79+ // ensure vpa crd is established and accepted on the cluster before continuing
80+ Eventually (func () (bool , error ) {
81+ crd , err := kubeClient .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), vpaCRD .GetName (), metav1.GetOptions {})
82+ if err != nil {
83+ return false , err
84+ }
85+ return crdReady (& crd .Status ), nil
86+ }).Should (BeTrue ())
87+
5188 var installPlanRef string
52- // create catalog source
5389 source := & v1alpha1.CatalogSource {
5490 TypeMeta : metav1.TypeMeta {
5591 Kind : v1alpha1 .CatalogSourceKind ,
@@ -66,8 +102,10 @@ var _ = PDescribe("Installing bundles with new object types", func() {
66102 },
67103 }
68104
69- source , err := operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
70- Expect (err ).ToNot (HaveOccurred (), "could not create catalog source" )
105+ Eventually (func () error {
106+ source , err = operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
107+ return err
108+ }).Should (Succeed ())
71109
72110 // Create a Subscription for package
73111 _ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
@@ -91,7 +129,7 @@ var _ = PDescribe("Installing bundles with new object types", func() {
91129 vpaVersion = "v1"
92130 vpaResource = "verticalpodautoscalers"
93131 pdbName = "busybox-pdb"
94- priorityClassName = "high -priority"
132+ priorityClassName = "super -priority"
95133 vpaName = "busybox-vpa"
96134 )
97135
@@ -117,5 +155,36 @@ var _ = PDescribe("Installing bundles with new object types", func() {
117155 return err
118156 }).Should (Succeed (), "expected no error finding vpa object associated with csv" )
119157 })
158+
159+ AfterEach (func () {
160+ By ("Deleting the VPA CRD" )
161+ Eventually (func () error {
162+ err := ctx .Ctx ().Client ().Delete (context .TODO (), & vpaCRD )
163+ if k8serrors .IsNotFound (err ) {
164+ return nil
165+ }
166+ return err
167+ }).Should (Succeed ())
168+ })
120169 })
121170})
171+
172+ func crdReady (status * apiextensionsv1beta1.CustomResourceDefinitionStatus ) bool {
173+ if status == nil {
174+ return false
175+ }
176+ established , namesAccepted := false , false
177+ for _ , cdt := range status .Conditions {
178+ switch cdt .Type {
179+ case apiextensionsv1beta1 .Established :
180+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
181+ established = true
182+ }
183+ case apiextensionsv1beta1 .NamesAccepted :
184+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
185+ namesAccepted = true
186+ }
187+ }
188+ }
189+ return established && namesAccepted
190+ }
0 commit comments