6
6
"encoding/json"
7
7
8
8
"github.com/ghodss/yaml"
9
+ corev1 "k8s.io/api/core/v1"
9
10
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
10
11
k8serrors "k8s.io/apimachinery/pkg/api/errors"
11
12
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -27,19 +28,23 @@ var vpaCRDRaw []byte
27
28
28
29
var _ = Describe ("Installing bundles with new object types" , func () {
29
30
var (
30
- kubeClient operatorclient.ClientInterface
31
- operatorClient versioned.Interface
32
- dynamicClient dynamic.Interface
31
+ kubeClient operatorclient.ClientInterface
32
+ operatorClient versioned.Interface
33
+ dynamicClient dynamic.Interface
34
+ generatedNamespace corev1.Namespace
33
35
)
34
36
35
37
BeforeEach (func () {
36
38
kubeClient = ctx .Ctx ().KubeClient ()
37
39
operatorClient = ctx .Ctx ().OperatorClient ()
38
40
dynamicClient = ctx .Ctx ().DynamicClient ()
41
+
42
+ By ("creating a test namespace" )
43
+ generatedNamespace = SetupGeneratedTestNamespace (genName ("bundle-e2e-" ))
39
44
})
40
45
41
46
AfterEach (func () {
42
- TearDown ( testNamespace )
47
+ TeardownNamespace ( & generatedNamespace )
43
48
})
44
49
45
50
When ("a bundle with a pdb, priorityclass, and VPA object is installed" , func () {
@@ -66,7 +71,7 @@ var _ = Describe("Installing bundles with new object types", func() {
66
71
Expect (err ).ToNot (HaveOccurred (), "could not convert vpa crd to unstructured" )
67
72
68
73
Eventually (func () error {
69
- err := ctx .Ctx ().Client ().Create (context .TODO (), & vpaCRD )
74
+ err := ctx .Ctx ().Client ().Create (context .Background (), & vpaCRD )
70
75
if err != nil {
71
76
if ! k8serrors .IsAlreadyExists (err ) {
72
77
return err
@@ -77,22 +82,21 @@ var _ = Describe("Installing bundles with new object types", func() {
77
82
78
83
// ensure vpa crd is established and accepted on the cluster before continuing
79
84
Eventually (func () (bool , error ) {
80
- crd , err := kubeClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), vpaCRD .GetName (), metav1.GetOptions {})
85
+ crd , err := kubeClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .Background (), vpaCRD .GetName (), metav1.GetOptions {})
81
86
if err != nil {
82
87
return false , err
83
88
}
84
89
return crdReady (& crd .Status ), nil
85
90
}).Should (BeTrue ())
86
91
87
- var installPlanRef string
88
92
source := & v1alpha1.CatalogSource {
89
93
TypeMeta : metav1.TypeMeta {
90
94
Kind : v1alpha1 .CatalogSourceKind ,
91
95
APIVersion : v1alpha1 .CatalogSourceCRDAPIVersion ,
92
96
},
93
97
ObjectMeta : metav1.ObjectMeta {
94
98
Name : sourceName ,
95
- Namespace : testNamespace ,
99
+ Namespace : generatedNamespace . GetName () ,
96
100
Labels : map [string ]string {"olm.catalogSource" : sourceName },
97
101
},
98
102
Spec : v1alpha1.CatalogSourceSpec {
@@ -102,7 +106,7 @@ var _ = Describe("Installing bundles with new object types", func() {
102
106
}
103
107
104
108
Eventually (func () error {
105
- source , err = operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
109
+ source , err = operatorClient .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .Background (), source , metav1.CreateOptions {})
106
110
return err
107
111
}).Should (Succeed ())
108
112
@@ -114,13 +118,13 @@ var _ = Describe("Installing bundles with new object types", func() {
114
118
_ = createSubscriptionForCatalog (operatorClient , source .GetNamespace (), subName , source .GetName (), packageName , channelName , "" , v1alpha1 .ApprovalAutomatic )
115
119
116
120
// Wait for the Subscription to succeed
117
- sub , err := fetchSubscription (operatorClient , testNamespace , subName , subscriptionStateAtLatestChecker )
121
+ sub , err := fetchSubscription (operatorClient , generatedNamespace . GetName () , subName , subscriptionStateAtLatestChecker )
118
122
Expect (err ).ToNot (HaveOccurred (), "could not get subscription at latest status" )
119
123
120
- installPlanRef = sub .Status .InstallPlanRef . Name
124
+ installPlanRef : = sub .Status .InstallPlanRef
121
125
122
126
// Wait for the installplan to complete (5 minute timeout)
123
- _ , err = fetchInstallPlan (GinkgoT (), operatorClient , installPlanRef , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
127
+ _ , err = fetchInstallPlanWithNamespace (GinkgoT (), operatorClient , installPlanRef . Name , installPlanRef . Namespace , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
124
128
Expect (err ).ToNot (HaveOccurred (), "could not get installplan at complete phase" )
125
129
126
130
ctx .Ctx ().Logf ("install plan %s completed" , installPlanRef )
@@ -144,25 +148,25 @@ var _ = Describe("Installing bundles with new object types", func() {
144
148
145
149
// confirm extra bundle objects are installed
146
150
Eventually (func () error {
147
- _ , err := kubeClient .KubernetesInterface ().SchedulingV1 ().PriorityClasses ().Get (context .TODO (), priorityClassName , metav1.GetOptions {})
151
+ _ , err := kubeClient .KubernetesInterface ().SchedulingV1 ().PriorityClasses ().Get (context .Background (), priorityClassName , metav1.GetOptions {})
148
152
return err
149
153
}).Should (Succeed (), "expected no error getting priorityclass object associated with CSV" )
150
154
151
155
Eventually (func () error {
152
- _ , err := dynamicClient .Resource (resource ).Namespace (testNamespace ) .Get (context .TODO (), vpaName , metav1.GetOptions {})
156
+ _ , err := dynamicClient .Resource (resource ).Namespace (generatedNamespace . GetName ()) .Get (context .Background (), vpaName , metav1.GetOptions {})
153
157
return err
154
158
}).Should (Succeed (), "expected no error finding vpa object associated with csv" )
155
159
156
160
Eventually (func () error {
157
- _ , err := kubeClient .KubernetesInterface ().PolicyV1 ().PodDisruptionBudgets (testNamespace ) .Get (context .TODO (), pdbName , metav1.GetOptions {})
161
+ _ , err := kubeClient .KubernetesInterface ().PolicyV1 ().PodDisruptionBudgets (generatedNamespace . GetName ()) .Get (context .Background (), pdbName , metav1.GetOptions {})
158
162
return err
159
163
}).Should (Succeed (), "expected no error getting pdb object associated with CSV" )
160
164
})
161
165
162
166
AfterEach (func () {
163
167
By ("Deleting the VPA CRD" )
164
168
Eventually (func () error {
165
- err := ctx .Ctx ().Client ().Delete (context .TODO (), & vpaCRD )
169
+ err := ctx .Ctx ().Client ().Delete (context .Background (), & vpaCRD )
166
170
if k8serrors .IsNotFound (err ) {
167
171
return nil
168
172
}
0 commit comments