@@ -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
1926var _ = Describe ("Installing bundles with new object types" , func () {
@@ -34,21 +41,50 @@ var _ = Describe("Installing bundles with new object types", func() {
3441 })
3542
3643 When ("a bundle with a pdb, priorityclass, and VPA object is installed" , func () {
37- By ("including the VPA CRD in the CSV" )
3844 const (
3945 packageName = "busybox"
4046 channelName = "alpha"
4147 subName = "test-subscription"
4248 )
49+ var vpaCRD unstructured.Unstructured
4350
4451 BeforeEach (func () {
52+ By ("first installing the VPA CRD on cluster" )
4553 const (
4654 sourceName = "test-catalog"
4755 imageName = "quay.io/olmtest/single-bundle-index:pdb"
4856 )
4957
58+ // create VPA CRD on cluster
59+ y , err := vpa .Asset ("test/e2e/testdata/vpa/crd.yaml" )
60+ Expect (err ).ToNot (HaveOccurred (), "could not read vpa bindata" )
61+
62+ data , err := yaml .YAMLToJSON (y )
63+ Expect (err ).ToNot (HaveOccurred (), "could not convert vpa crd to json" )
64+
65+ err = json .Unmarshal (data , & vpaCRD )
66+ Expect (err ).ToNot (HaveOccurred (), "could not convert vpa crd to unstructured" )
67+
68+ Eventually (func () error {
69+ err := ctx .Ctx ().Client ().Create (context .TODO (), & vpaCRD )
70+ if err != nil {
71+ if ! k8serrors .IsAlreadyExists (err ) {
72+ return err
73+ }
74+ }
75+ return nil
76+ }).Should (Succeed ())
77+
78+ // ensure vpa crd is established and accepted on the cluster before continuing
79+ Eventually (func () (bool , error ) {
80+ crd , err := kubeClient .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), vpaCRD .GetName (), metav1.GetOptions {})
81+ if err != nil {
82+ return false , err
83+ }
84+ return crdReady (& crd .Status ), nil
85+ }).Should (BeTrue ())
86+
5087 var installPlanRef string
51- // create catalog source
5288 source := & v1alpha1.CatalogSource {
5389 TypeMeta : metav1.TypeMeta {
5490 Kind : v1alpha1 .CatalogSourceKind ,
@@ -65,8 +101,10 @@ var _ = Describe("Installing bundles with new object types", func() {
65101 },
66102 }
67103
68- source , err := operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
69- Expect (err ).ToNot (HaveOccurred (), "could not create catalog source" )
104+ Eventually (func () error {
105+ source , err = operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
106+ return err
107+ }).Should (Succeed ())
70108
71109 // Create a Subscription for package
72110 _ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
@@ -90,7 +128,7 @@ var _ = Describe("Installing bundles with new object types", func() {
90128 vpaVersion = "v1"
91129 vpaResource = "verticalpodautoscalers"
92130 pdbName = "busybox-pdb"
93- priorityClassName = "high -priority"
131+ priorityClassName = "super -priority"
94132 vpaName = "busybox-vpa"
95133 )
96134
@@ -116,5 +154,36 @@ var _ = Describe("Installing bundles with new object types", func() {
116154 return err
117155 }).Should (Succeed (), "expected no error finding vpa object associated with csv" )
118156 })
157+
158+ AfterEach (func () {
159+ By ("Deleting the VPA CRD" )
160+ Eventually (func () error {
161+ err := ctx .Ctx ().Client ().Delete (context .TODO (), & vpaCRD )
162+ if k8serrors .IsNotFound (err ) {
163+ return nil
164+ }
165+ return err
166+ }).Should (Succeed ())
167+ })
119168 })
120169})
170+
171+ func crdReady (status * apiextensionsv1beta1.CustomResourceDefinitionStatus ) bool {
172+ if status == nil {
173+ return false
174+ }
175+ established , namesAccepted := false , false
176+ for _ , cdt := range status .Conditions {
177+ switch cdt .Type {
178+ case apiextensionsv1beta1 .Established :
179+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
180+ established = true
181+ }
182+ case apiextensionsv1beta1 .NamesAccepted :
183+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
184+ namesAccepted = true
185+ }
186+ }
187+ }
188+ return established && namesAccepted
189+ }
0 commit comments