@@ -2,6 +2,12 @@ package e2e
2
2
3
3
import (
4
4
"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"
5
11
6
12
. "github.com/onsi/ginkgo"
7
13
. "github.com/onsi/gomega"
@@ -14,6 +20,7 @@ import (
14
20
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
15
21
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
16
22
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
23
+ "github.com/operator-framework/operator-lifecycle-manager/test/e2e/testdata/vpa"
17
24
)
18
25
19
26
var _ = Describe ("Installing bundles with new object types" , func () {
@@ -34,21 +41,50 @@ var _ = Describe("Installing bundles with new object types", func() {
34
41
})
35
42
36
43
When ("a bundle with a pdb, priorityclass, and VPA object is installed" , func () {
37
- By ("including the VPA CRD in the CSV" )
38
44
const (
39
45
packageName = "busybox"
40
46
channelName = "alpha"
41
47
subName = "test-subscription"
42
48
)
49
+ var vpaCRD unstructured.Unstructured
43
50
44
51
BeforeEach (func () {
52
+ By ("first installing the VPA CRD on cluster" )
45
53
const (
46
54
sourceName = "test-catalog"
47
55
imageName = "quay.io/olmtest/single-bundle-index:pdb"
48
56
)
49
57
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
+
50
87
var installPlanRef string
51
- // create catalog source
52
88
source := & v1alpha1.CatalogSource {
53
89
TypeMeta : metav1.TypeMeta {
54
90
Kind : v1alpha1 .CatalogSourceKind ,
@@ -65,8 +101,10 @@ var _ = Describe("Installing bundles with new object types", func() {
65
101
},
66
102
}
67
103
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 ())
70
108
71
109
// Create a Subscription for package
72
110
_ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
@@ -90,7 +128,7 @@ var _ = Describe("Installing bundles with new object types", func() {
90
128
vpaVersion = "v1"
91
129
vpaResource = "verticalpodautoscalers"
92
130
pdbName = "busybox-pdb"
93
- priorityClassName = "high -priority"
131
+ priorityClassName = "super -priority"
94
132
vpaName = "busybox-vpa"
95
133
)
96
134
@@ -116,5 +154,36 @@ var _ = Describe("Installing bundles with new object types", func() {
116
154
return err
117
155
}).Should (Succeed (), "expected no error finding vpa object associated with csv" )
118
156
})
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
+ })
119
168
})
120
169
})
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