@@ -2,6 +2,13 @@ package e2e
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
6
+ "io/ioutil"
7
+
8
+ "github.com/ghodss/yaml"
9
+ apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
10
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
11
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
5
12
6
13
. "github.com/onsi/ginkgo"
7
14
. "github.com/onsi/gomega"
@@ -34,19 +41,49 @@ 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 u 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 := ioutil .ReadFile ("data/vpa/crd.yaml" )
60
+ Expect (err ).ToNot (HaveOccurred (), "could not convert read vpa crd" )
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 , & u )
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 (), & u )
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 (), u .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
88
// create catalog source
52
89
source := & v1alpha1.CatalogSource {
@@ -65,8 +102,10 @@ var _ = Describe("Installing bundles with new object types", func() {
65
102
},
66
103
}
67
104
68
- source , err := operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
69
- 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 ())
70
109
71
110
// Create a Subscription for package
72
111
_ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
@@ -116,5 +155,33 @@ var _ = Describe("Installing bundles with new object types", func() {
116
155
return err
117
156
}).Should (Succeed (), "expected no error finding vpa object associated with csv" )
118
157
})
158
+
159
+ AfterEach (func () {
160
+ By ("Deleting the VPA CRD" )
161
+ Eventually (func () error {
162
+ err := ctx .Ctx ().Client ().Delete (context .TODO (), & u )
163
+ return err
164
+ }).Should (Succeed ())
165
+ })
119
166
})
120
167
})
168
+
169
+ func crdReady (status * apiextensionsv1beta1.CustomResourceDefinitionStatus ) bool {
170
+ if status == nil {
171
+ return false
172
+ }
173
+ established , namesAccepted := false , false
174
+ for _ , cdt := range status .Conditions {
175
+ switch cdt .Type {
176
+ case apiextensionsv1beta1 .Established :
177
+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
178
+ established = true
179
+ }
180
+ case apiextensionsv1beta1 .NamesAccepted :
181
+ if cdt .Status == apiextensionsv1beta1 .ConditionTrue {
182
+ namesAccepted = true
183
+ }
184
+ }
185
+ }
186
+ return established && namesAccepted
187
+ }
0 commit comments