@@ -13,6 +13,7 @@ import (
13
13
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
14
14
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/apis/rbac"
15
15
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
16
+ "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
16
17
"github.com/stretchr/testify/assert"
17
18
"github.com/stretchr/testify/require"
18
19
corev1 "k8s.io/api/core/v1"
@@ -23,56 +24,67 @@ import (
23
24
)
24
25
25
26
var _ = Describe ("User defined service account" , func () {
27
+ var (
28
+ generatedNamespace corev1.Namespace
29
+ )
30
+
31
+ BeforeEach (func () {
32
+ generatedNamespace = corev1.Namespace {
33
+ ObjectMeta : metav1.ObjectMeta {
34
+ Name : genName ("user-defined-sa-e2e-" ),
35
+ },
36
+ }
37
+ Eventually (func () error {
38
+ return ctx .Ctx ().Client ().Create (context .Background (), & generatedNamespace )
39
+ }).Should (Succeed ())
40
+ })
41
+
26
42
AfterEach (func () {
27
- TearDown ( testNamespace )
43
+ TeardownNamespace ( generatedNamespace . GetName () )
28
44
})
29
45
30
46
It ("with no permission" , func () {
31
47
32
48
kubeclient := newKubeClient ()
33
49
crclient := newCRClient ()
34
50
35
- namespace := genName ("scoped-ns-" )
36
- _ , cleanupNS := newNamespace (kubeclient , namespace )
37
- defer cleanupNS ()
38
-
39
51
// Create a service account, but add no permission to it.
40
52
saName := genName ("scoped-sa-" )
41
- _ , cleanupSA := newServiceAccount (kubeclient , namespace , saName )
53
+ _ , cleanupSA := newServiceAccount (kubeclient , generatedNamespace . GetName () , saName )
42
54
defer cleanupSA ()
43
55
44
56
// Add an OperatorGroup and specify the service account.
45
57
ogName := genName ("scoped-og-" )
46
- _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , namespace , ogName , saName )
58
+ _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , generatedNamespace . GetName () , ogName , saName )
47
59
defer cleanupOG ()
48
60
49
61
permissions := deploymentPermissions ()
50
- catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , namespace , permissions )
62
+ catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , generatedNamespace . GetName () , permissions )
51
63
defer catsrcCleanup ()
52
64
53
65
// Ensure that the catalog source is resolved before we create a subscription.
54
- _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), namespace , catalogSourceRegistryPodSynced )
66
+ _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), generatedNamespace . GetName () , catalogSourceRegistryPodSynced )
55
67
require .NoError (GinkgoT (), err )
56
68
57
69
subscriptionName := genName ("scoped-sub-" )
58
- cleanupSubscription := createSubscriptionForCatalog (crclient , namespace , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
70
+ cleanupSubscription := createSubscriptionForCatalog (crclient , generatedNamespace . GetName () , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
59
71
defer cleanupSubscription ()
60
72
61
73
// Wait until an install plan is created.
62
- subscription , err := fetchSubscription (crclient , namespace , subscriptionName , subscriptionHasInstallPlanChecker )
74
+ subscription , err := fetchSubscription (crclient , generatedNamespace . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
63
75
require .NoError (GinkgoT (), err )
64
76
require .NotNil (GinkgoT (), subscription )
65
77
66
78
// We expect the InstallPlan to be in status: Failed.
67
79
ipName := subscription .Status .Install .Name
68
80
ipPhaseCheckerFunc := buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseFailed )
69
- ipGot , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipName , namespace , ipPhaseCheckerFunc )
81
+ ipGot , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipName , generatedNamespace . GetName () , ipPhaseCheckerFunc )
70
82
require .NoError (GinkgoT (), err )
71
83
72
84
conditionGot := mustHaveCondition (GinkgoT (), ipGot , v1alpha1 .InstallPlanInstalled )
73
85
assert .Equal (GinkgoT (), corev1 .ConditionFalse , conditionGot .Status )
74
86
assert .Equal (GinkgoT (), v1alpha1 .InstallPlanReasonComponentFailed , conditionGot .Reason )
75
- assert .Contains (GinkgoT (), conditionGot .Message , fmt .Sprintf ("is forbidden: User \" system:serviceaccount:%s:%s\" cannot create resource" , namespace , saName ))
87
+ assert .Contains (GinkgoT (), conditionGot .Message , fmt .Sprintf ("is forbidden: User \" system:serviceaccount:%s:%s\" cannot create resource" , generatedNamespace . GetName () , saName ))
76
88
77
89
// Verify that all step resources are in Unknown state.
78
90
for _ , step := range ipGot .Status .Plan {
@@ -85,43 +97,39 @@ var _ = Describe("User defined service account", func() {
85
97
kubeclient := newKubeClient ()
86
98
crclient := newCRClient ()
87
99
88
- namespace := genName ("scoped-ns-" )
89
- _ , cleanupNS := newNamespace (kubeclient , namespace )
90
- defer cleanupNS ()
91
-
92
100
// Create a service account, add enough permission to it so that operator install is successful.
93
101
saName := genName ("scoped-sa" )
94
- _ , cleanupSA := newServiceAccount (kubeclient , namespace , saName )
102
+ _ , cleanupSA := newServiceAccount (kubeclient , generatedNamespace . GetName () , saName )
95
103
defer cleanupSA ()
96
- cleanupPerm := grantPermission (GinkgoT (), kubeclient , namespace , saName )
104
+ cleanupPerm := grantPermission (GinkgoT (), kubeclient , generatedNamespace . GetName () , saName )
97
105
defer cleanupPerm ()
98
106
99
107
// Add an OperatorGroup and specify the service account.
100
108
ogName := genName ("scoped-og-" )
101
- _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , namespace , ogName , saName )
109
+ _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , generatedNamespace . GetName () , ogName , saName )
102
110
defer cleanupOG ()
103
111
104
112
permissions := deploymentPermissions ()
105
- catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , namespace , permissions )
113
+ catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , generatedNamespace . GetName () , permissions )
106
114
defer catsrcCleanup ()
107
115
108
116
// Ensure that the catalog source is resolved before we create a subscription.
109
- _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), namespace , catalogSourceRegistryPodSynced )
117
+ _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), generatedNamespace . GetName () , catalogSourceRegistryPodSynced )
110
118
require .NoError (GinkgoT (), err )
111
119
112
120
subscriptionName := genName ("scoped-sub-" )
113
- cleanupSubscription := createSubscriptionForCatalog (crclient , namespace , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
121
+ cleanupSubscription := createSubscriptionForCatalog (crclient , generatedNamespace . GetName () , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
114
122
defer cleanupSubscription ()
115
123
116
124
// Wait until an install plan is created.
117
- subscription , err := fetchSubscription (crclient , namespace , subscriptionName , subscriptionHasInstallPlanChecker )
125
+ subscription , err := fetchSubscription (crclient , generatedNamespace . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
118
126
require .NoError (GinkgoT (), err )
119
127
require .NotNil (GinkgoT (), subscription )
120
128
121
129
// We expect the InstallPlan to be in status: Complete.
122
130
ipName := subscription .Status .Install .Name
123
131
ipPhaseCheckerFunc := buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete )
124
- ipGot , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipName , namespace , ipPhaseCheckerFunc )
132
+ ipGot , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipName , generatedNamespace . GetName () , ipPhaseCheckerFunc )
125
133
require .NoError (GinkgoT (), err )
126
134
127
135
conditionGot := mustHaveCondition (GinkgoT (), ipGot , v1alpha1 .InstallPlanInstalled )
@@ -141,50 +149,46 @@ var _ = Describe("User defined service account", func() {
141
149
kubeclient := newKubeClient ()
142
150
crclient := newCRClient ()
143
151
144
- namespace := genName ("scoped-ns-" )
145
- _ , cleanupNS := newNamespace (kubeclient , namespace )
146
- defer cleanupNS ()
147
-
148
152
// Create a service account, but add no permission to it.
149
153
saName := genName ("scoped-sa-" )
150
- _ , cleanupSA := newServiceAccount (kubeclient , namespace , saName )
154
+ _ , cleanupSA := newServiceAccount (kubeclient , generatedNamespace . GetName () , saName )
151
155
defer cleanupSA ()
152
156
153
157
// Add an OperatorGroup and specify the service account.
154
158
ogName := genName ("scoped-og-" )
155
- _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , namespace , ogName , saName )
159
+ _ , cleanupOG := newOperatorGroupWithServiceAccount (crclient , generatedNamespace . GetName () , ogName , saName )
156
160
defer cleanupOG ()
157
161
158
162
permissions := deploymentPermissions ()
159
- catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , namespace , permissions )
163
+ catsrc , subSpec , catsrcCleanup := newCatalogSource (GinkgoT (), kubeclient , crclient , "scoped" , generatedNamespace . GetName () , permissions )
160
164
defer catsrcCleanup ()
161
165
162
166
// Ensure that the catalog source is resolved before we create a subscription.
163
- _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), namespace , catalogSourceRegistryPodSynced )
167
+ _ , err := fetchCatalogSourceOnStatus (crclient , catsrc .GetName (), generatedNamespace . GetName () , catalogSourceRegistryPodSynced )
164
168
require .NoError (GinkgoT (), err )
165
169
166
170
subscriptionName := genName ("scoped-sub-" )
167
- cleanupSubscription := createSubscriptionForCatalog (crclient , namespace , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
171
+ cleanupSubscription := createSubscriptionForCatalog (crclient , generatedNamespace . GetName () , subscriptionName , catsrc .GetName (), subSpec .Package , subSpec .Channel , subSpec .StartingCSV , subSpec .InstallPlanApproval )
168
172
defer cleanupSubscription ()
169
173
170
174
// Wait until an install plan is created.
171
- subscription , err := fetchSubscription (crclient , namespace , subscriptionName , subscriptionHasInstallPlanChecker )
175
+ subscription , err := fetchSubscription (crclient , generatedNamespace . GetName () , subscriptionName , subscriptionHasInstallPlanChecker )
172
176
require .NoError (GinkgoT (), err )
173
177
require .NotNil (GinkgoT (), subscription )
174
178
175
179
// We expect the InstallPlan to be in status: Failed.
176
180
ipNameOld := subscription .Status .InstallPlanRef .Name
177
181
ipPhaseCheckerFunc := buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseFailed )
178
- ipGotOld , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipNameOld , namespace , ipPhaseCheckerFunc )
182
+ ipGotOld , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipNameOld , generatedNamespace . GetName () , ipPhaseCheckerFunc )
179
183
require .NoError (GinkgoT (), err )
180
184
require .Equal (GinkgoT (), v1alpha1 .InstallPlanPhaseFailed , ipGotOld .Status .Phase )
181
185
182
186
// Grant permission now and this should trigger an retry of InstallPlan.
183
- cleanupPerm := grantPermission (GinkgoT (), kubeclient , namespace , saName )
187
+ cleanupPerm := grantPermission (GinkgoT (), kubeclient , generatedNamespace . GetName () , saName )
184
188
defer cleanupPerm ()
185
189
186
190
ipPhaseCheckerFunc = buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete )
187
- ipGotNew , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipNameOld , namespace , ipPhaseCheckerFunc )
191
+ ipGotNew , err := fetchInstallPlanWithNamespace (GinkgoT (), crclient , ipNameOld , generatedNamespace . GetName () , ipPhaseCheckerFunc )
188
192
require .NoError (GinkgoT (), err )
189
193
require .Equal (GinkgoT (), v1alpha1 .InstallPlanPhaseComplete , ipGotNew .Status .Phase )
190
194
})
0 commit comments