@@ -17,15 +17,13 @@ import (
17
17
"helm.sh/helm/v3/pkg/storage/driver"
18
18
corev1 "k8s.io/api/core/v1"
19
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
- featuregatetesting "k8s.io/component-base/featuregate/testing"
21
20
"sigs.k8s.io/controller-runtime/pkg/client"
22
21
23
22
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
24
23
25
24
ocv1 "github.com/operator-framework/operator-controller/api/v1"
26
25
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
27
26
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
28
- "github.com/operator-framework/operator-controller/internal/operator-controller/features"
29
27
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
30
28
)
31
29
@@ -45,6 +43,17 @@ func (p *noOpPreAuthorizer) PreAuthorize(
45
43
return nil , nil
46
44
}
47
45
46
+ type errorPreAuthorizer struct {}
47
+
48
+ func (p * errorPreAuthorizer ) PreAuthorize (
49
+ ctx context.Context ,
50
+ ext * ocv1.ClusterExtension ,
51
+ manifestReader io.Reader ,
52
+ ) ([]authorization.ScopedPolicyRules , error ) {
53
+ // Always returns no missing rules and an error
54
+ return nil , errors .New ("problem running preauthorization" )
55
+ }
56
+
48
57
func (mp * mockPreflight ) Install (context.Context , * release.Release ) error {
49
58
return mp .installErr
50
59
}
@@ -270,7 +279,6 @@ func TestApply_Installation(t *testing.T) {
270
279
}
271
280
272
281
func TestApply_InstallationWithPreflightPermissionsEnabled (t * testing.T ) {
273
- featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .PreflightPermissions , true )
274
282
275
283
t .Run ("fails during dry-run installation" , func (t * testing.T ) {
276
284
mockAcg := & mockActionGetter {
@@ -313,18 +321,17 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
313
321
require .Nil (t , objs )
314
322
})
315
323
316
- t .Run ("fails during installation" , func (t * testing.T ) {
324
+ t .Run ("fails during installation because of missing RBAC rules " , func (t * testing.T ) {
317
325
mockAcg := & mockActionGetter {
318
326
getClientErr : driver .ErrReleaseNotFound ,
319
- installErr : errors .New ("failed installing chart" ),
320
327
desiredRel : & release.Release {
321
328
Info : & release.Info {Status : release .StatusDeployed },
322
329
Manifest : validManifest ,
323
330
},
324
331
}
325
332
helmApplier := applier.Helm {
326
333
ActionClientGetter : mockAcg ,
327
- PreAuthorizer : & noOpPreAuthorizer {},
334
+ PreAuthorizer : & errorPreAuthorizer {},
328
335
BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
329
336
}
330
337
// Use a ClusterExtension with valid Spec fields.
@@ -338,8 +345,37 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
338
345
}
339
346
objs , state , err := helmApplier .Apply (context .TODO (), validFS , validCE , testObjectLabels , testStorageLabels )
340
347
require .Error (t , err )
341
- require .ErrorContains (t , err , "installing chart" )
342
- require .Equal (t , applier .StateNeedsInstall , state )
348
+ require .ErrorContains (t , err , "problem running preauthorization" )
349
+ require .Equal (t , "" , state )
350
+ require .Nil (t , objs )
351
+ })
352
+
353
+ t .Run ("fails during installation because of pre-authorization failure" , func (t * testing.T ) {
354
+ mockAcg := & mockActionGetter {
355
+ getClientErr : driver .ErrReleaseNotFound ,
356
+ desiredRel : & release.Release {
357
+ Info : & release.Info {Status : release .StatusDeployed },
358
+ Manifest : validManifest ,
359
+ },
360
+ }
361
+ helmApplier := applier.Helm {
362
+ ActionClientGetter : mockAcg ,
363
+ PreAuthorizer : & errorPreAuthorizer {},
364
+ BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
365
+ }
366
+ // Use a ClusterExtension with valid Spec fields.
367
+ validCE := & ocv1.ClusterExtension {
368
+ Spec : ocv1.ClusterExtensionSpec {
369
+ Namespace : "default" ,
370
+ ServiceAccount : ocv1.ServiceAccountReference {
371
+ Name : "default" ,
372
+ },
373
+ },
374
+ }
375
+ objs , state , err := helmApplier .Apply (context .TODO (), validFS , validCE , testObjectLabels , testStorageLabels )
376
+ require .Error (t , err )
377
+ require .ErrorContains (t , err , "problem running preauthorization" )
378
+ require .Equal (t , "" , state )
343
379
require .Nil (t , objs )
344
380
})
345
381
@@ -488,7 +524,6 @@ func TestApply_Upgrade(t *testing.T) {
488
524
}
489
525
490
526
func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled (t * testing.T ) {
491
- featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .SingleOwnNamespaceInstallSupport , true )
492
527
493
528
t .Run ("generates bundle resources using the configured watch namespace" , func (t * testing.T ) {
494
529
var expectedWatchNamespace = "watch-namespace"
0 commit comments