@@ -3,7 +3,6 @@ package applier_test
3
3
import (
4
4
"context"
5
5
"errors"
6
- "fmt"
7
6
"io"
8
7
"os"
9
8
"testing"
@@ -14,11 +13,7 @@ import (
14
13
"helm.sh/helm/v3/pkg/chart"
15
14
"helm.sh/helm/v3/pkg/release"
16
15
"helm.sh/helm/v3/pkg/storage/driver"
17
- corev1 "k8s.io/api/core/v1"
18
16
rbacv1 "k8s.io/api/rbac/v1"
19
- apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
20
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
- featuregatetesting "k8s.io/component-base/featuregate/testing"
22
17
"sigs.k8s.io/controller-runtime/pkg/client"
23
18
24
19
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
@@ -28,10 +23,7 @@ import (
28
23
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
29
24
"github.com/operator-framework/operator-controller/internal/operator-controller/contentmanager"
30
25
cmcache "github.com/operator-framework/operator-controller/internal/operator-controller/contentmanager/cache"
31
- "github.com/operator-framework/operator-controller/internal/operator-controller/features"
32
- registryv1Bundle "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
33
26
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
34
- "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
35
27
)
36
28
37
29
var _ contentmanager.Manager = (* mockManagedContentCacheManager )(nil )
@@ -246,8 +238,8 @@ func TestApply_Base(t *testing.T) {
246
238
t .Run ("fails trying to obtain an action client" , func (t * testing.T ) {
247
239
mockAcg := & mockActionGetter {actionClientForErr : errors .New ("failed getting action client" )}
248
240
helmApplier := applier.Helm {
249
- ActionClientGetter : mockAcg ,
250
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
241
+ ActionClientGetter : mockAcg ,
242
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
251
243
}
252
244
253
245
installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -260,8 +252,8 @@ func TestApply_Base(t *testing.T) {
260
252
t .Run ("fails getting current release and !driver.ErrReleaseNotFound" , func (t * testing.T ) {
261
253
mockAcg := & mockActionGetter {getClientErr : errors .New ("failed getting current release" )}
262
254
helmApplier := applier.Helm {
263
- ActionClientGetter : mockAcg ,
264
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
255
+ ActionClientGetter : mockAcg ,
256
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
265
257
}
266
258
267
259
installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -279,8 +271,8 @@ func TestApply_Installation(t *testing.T) {
279
271
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
280
272
}
281
273
helmApplier := applier.Helm {
282
- ActionClientGetter : mockAcg ,
283
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
274
+ ActionClientGetter : mockAcg ,
275
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
284
276
}
285
277
286
278
installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -299,7 +291,7 @@ func TestApply_Installation(t *testing.T) {
299
291
helmApplier := applier.Helm {
300
292
ActionClientGetter : mockAcg ,
301
293
Preflights : []applier.Preflight {mockPf },
302
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
294
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
303
295
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
304
296
}
305
297
@@ -317,7 +309,7 @@ func TestApply_Installation(t *testing.T) {
317
309
}
318
310
helmApplier := applier.Helm {
319
311
ActionClientGetter : mockAcg ,
320
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
312
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
321
313
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
322
314
}
323
315
@@ -338,7 +330,7 @@ func TestApply_Installation(t *testing.T) {
338
330
}
339
331
helmApplier := applier.Helm {
340
332
ActionClientGetter : mockAcg ,
341
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
333
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
342
334
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
343
335
Manager : & mockManagedContentCacheManager {
344
336
cache : & mockManagedContentCache {},
@@ -359,8 +351,8 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
359
351
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
360
352
}
361
353
helmApplier := applier.Helm {
362
- ActionClientGetter : mockAcg ,
363
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
354
+ ActionClientGetter : mockAcg ,
355
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
364
356
}
365
357
366
358
installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -384,7 +376,7 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
384
376
ActionClientGetter : mockAcg ,
385
377
Preflights : []applier.Preflight {mockPf },
386
378
PreAuthorizer : & mockPreAuthorizer {nil , nil },
387
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
379
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
388
380
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
389
381
}
390
382
@@ -404,9 +396,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
404
396
},
405
397
}
406
398
helmApplier := applier.Helm {
407
- ActionClientGetter : mockAcg ,
408
- PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
409
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
399
+ ActionClientGetter : mockAcg ,
400
+ PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
401
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
410
402
}
411
403
// Use a ClusterExtension with valid Spec fields.
412
404
validCE := & ocv1.ClusterExtension {
@@ -433,9 +425,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
433
425
},
434
426
}
435
427
helmApplier := applier.Helm {
436
- ActionClientGetter : mockAcg ,
437
- PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
438
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
428
+ ActionClientGetter : mockAcg ,
429
+ PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
430
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
439
431
}
440
432
// Use a ClusterExtension with valid Spec fields.
441
433
validCE := & ocv1.ClusterExtension {
@@ -464,7 +456,7 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
464
456
helmApplier := applier.Helm {
465
457
ActionClientGetter : mockAcg ,
466
458
PreAuthorizer : & mockPreAuthorizer {nil , nil },
467
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
459
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
468
460
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
469
461
Manager : & mockManagedContentCacheManager {
470
462
cache : & mockManagedContentCache {},
@@ -498,8 +490,8 @@ func TestApply_Upgrade(t *testing.T) {
498
490
dryRunUpgradeErr : errors .New ("failed attempting to dry-run upgrade chart" ),
499
491
}
500
492
helmApplier := applier.Helm {
501
- ActionClientGetter : mockAcg ,
502
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
493
+ ActionClientGetter : mockAcg ,
494
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
503
495
}
504
496
505
497
installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -522,7 +514,7 @@ func TestApply_Upgrade(t *testing.T) {
522
514
helmApplier := applier.Helm {
523
515
ActionClientGetter : mockAcg ,
524
516
Preflights : []applier.Preflight {mockPf },
525
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
517
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
526
518
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
527
519
}
528
520
@@ -545,7 +537,7 @@ func TestApply_Upgrade(t *testing.T) {
545
537
mockPf := & mockPreflight {}
546
538
helmApplier := applier.Helm {
547
539
ActionClientGetter : mockAcg , Preflights : []applier.Preflight {mockPf },
548
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
540
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
549
541
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
550
542
}
551
543
@@ -569,7 +561,7 @@ func TestApply_Upgrade(t *testing.T) {
569
561
helmApplier := applier.Helm {
570
562
ActionClientGetter : mockAcg ,
571
563
Preflights : []applier.Preflight {mockPf },
572
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
564
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
573
565
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
574
566
}
575
567
@@ -590,7 +582,7 @@ func TestApply_Upgrade(t *testing.T) {
590
582
}
591
583
helmApplier := applier.Helm {
592
584
ActionClientGetter : mockAcg ,
593
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
585
+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
594
586
HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
595
587
Manager : & mockManagedContentCacheManager {
596
588
cache : & mockManagedContentCache {},
@@ -604,53 +596,8 @@ func TestApply_Upgrade(t *testing.T) {
604
596
})
605
597
}
606
598
607
- func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled (t * testing.T ) {
608
- featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .SingleOwnNamespaceInstallSupport , true )
609
- t .Run ("generates bundle resources using the configured watch namespace" , func (t * testing.T ) {
610
- var expectedWatchNamespace = "watch-namespace"
611
-
612
- helmApplier := applier.Helm {
613
- ActionClientGetter : & mockActionGetter {
614
- getClientErr : driver .ErrReleaseNotFound ,
615
- desiredRel : & release.Release {
616
- Info : & release.Info {Status : release .StatusDeployed },
617
- Manifest : validManifest ,
618
- },
619
- },
620
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
621
- fn : func (bundle source.BundleSource , installNamespace string , config map [string ]interface {}) (* chart.Chart , error ) {
622
- require .Equal (t , expectedWatchNamespace , config [registryv1Bundle .BundleConfigWatchNamespaceKey ])
623
- return nil , nil
624
- },
625
- },
626
- HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
627
- Manager : & mockManagedContentCacheManager {
628
- cache : & mockManagedContentCache {},
629
- },
630
- }
631
-
632
- testExt := & ocv1.ClusterExtension {
633
- ObjectMeta : metav1.ObjectMeta {
634
- Name : "testExt" ,
635
- },
636
- Spec : ocv1.ClusterExtensionSpec {
637
- Config : & ocv1.ClusterExtensionConfig {
638
- ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
639
- Inline : & apiextensionsv1.JSON {
640
- Raw : []byte (fmt .Sprintf (`{"%s":"%s"}` , registryv1Bundle .BundleConfigWatchNamespaceKey , expectedWatchNamespace )),
641
- },
642
- },
643
- },
644
- }
645
-
646
- _ , _ , _ = helmApplier .Apply (context .TODO (), validFS , testExt , testObjectLabels , testStorageLabels )
647
- })
648
- }
649
-
650
599
func TestApply_RegistryV1ToChartConverterIntegration (t * testing.T ) {
651
600
t .Run ("generates bundle resources in AllNamespaces install mode" , func (t * testing.T ) {
652
- var expectedWatchNamespace = corev1 .NamespaceAll
653
-
654
601
helmApplier := applier.Helm {
655
602
ActionClientGetter : & mockActionGetter {
656
603
getClientErr : driver .ErrReleaseNotFound ,
@@ -659,9 +606,9 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
659
606
Manifest : validManifest ,
660
607
},
661
608
},
662
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
663
- fn : func (bundle source.BundleSource , installNamespace string , config map [ string ] interface {} ) (* chart.Chart , error ) {
664
- require .Equal (t , expectedWatchNamespace , config [ registryv1Bundle . BundleConfigWatchNamespaceKey ] )
609
+ HelmChartProvider : & fakeRegistryV1HelmChartProvider {
610
+ fn : func (bundle source.BundleSource , ext * ocv1. ClusterExtension ) (* chart.Chart , error ) {
611
+ require .Equal (t , testCE , ext )
665
612
return nil , nil
666
613
},
667
614
},
@@ -683,8 +630,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
683
630
Manifest : validManifest ,
684
631
},
685
632
},
686
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
687
- fn : func (bundle source.BundleSource , installNamespace string , config map [ string ] interface {} ) (* chart.Chart , error ) {
633
+ HelmChartProvider : & fakeRegistryV1HelmChartProvider {
634
+ fn : func (bundle source.BundleSource , ext * ocv1. ClusterExtension ) (* chart.Chart , error ) {
688
635
return nil , errors .New ("some error" )
689
636
},
690
637
},
@@ -698,10 +645,10 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
698
645
})
699
646
}
700
647
701
- type fakeBundleToHelmChartConverter struct {
702
- fn func (source.BundleSource , string , map [ string ] interface {} ) (* chart.Chart , error )
648
+ type fakeRegistryV1HelmChartProvider struct {
649
+ fn func (source.BundleSource , * ocv1. ClusterExtension ) (* chart.Chart , error )
703
650
}
704
651
705
- func (f fakeBundleToHelmChartConverter ) ToHelmChart (bundle source.BundleSource , installNamespace string , config map [ string ] interface {} ) (* chart.Chart , error ) {
706
- return f .fn (bundle , installNamespace , config )
652
+ func (f fakeRegistryV1HelmChartProvider ) Get (bundle source.BundleSource , ext * ocv1. ClusterExtension ) (* chart.Chart , error ) {
653
+ return f .fn (bundle , ext )
707
654
}
0 commit comments