@@ -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
// FIXME: Reintegrate this test
@@ -35,21 +42,50 @@ var _ = PDescribe("Installing bundles with new object types", func() {
35
42
})
36
43
37
44
When ("a bundle with a pdb, priorityclass, and VPA object is installed" , func () {
38
- By ("including the VPA CRD in the CSV" )
39
45
const (
40
46
packageName = "busybox"
41
47
channelName = "alpha"
42
48
subName = "test-subscription"
43
49
)
50
+ var vpaCRD unstructured.Unstructured
44
51
45
52
BeforeEach (func () {
53
+ By ("first installing the VPA CRD on cluster" )
46
54
const (
47
55
sourceName = "test-catalog"
48
56
imageName = "quay.io/olmtest/single-bundle-index:pdb"
49
57
)
50
58
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
+
51
88
var installPlanRef string
52
- // create catalog source
53
89
source := & v1alpha1.CatalogSource {
54
90
TypeMeta : metav1.TypeMeta {
55
91
Kind : v1alpha1 .CatalogSourceKind ,
@@ -66,8 +102,10 @@ var _ = PDescribe("Installing bundles with new object types", func() {
66
102
},
67
103
}
68
104
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 ())
71
109
72
110
// Create a Subscription for package
73
111
_ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
@@ -91,7 +129,7 @@ var _ = PDescribe("Installing bundles with new object types", func() {
91
129
vpaVersion = "v1"
92
130
vpaResource = "verticalpodautoscalers"
93
131
pdbName = "busybox-pdb"
94
- priorityClassName = "high -priority"
132
+ priorityClassName = "super -priority"
95
133
vpaName = "busybox-vpa"
96
134
)
97
135
@@ -117,5 +155,36 @@ var _ = PDescribe("Installing bundles with new object types", func() {
117
155
return err
118
156
}).Should (Succeed (), "expected no error finding vpa object associated with csv" )
119
157
})
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
+ })
120
169
})
121
170
})
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