@@ -3,7 +3,6 @@ package applier_test
33import (
44 "context"
55 "errors"
6- "fmt"
76 "io"
87 "os"
98 "testing"
@@ -14,11 +13,7 @@ import (
1413 "helm.sh/helm/v3/pkg/chart"
1514 "helm.sh/helm/v3/pkg/release"
1615 "helm.sh/helm/v3/pkg/storage/driver"
17- corev1 "k8s.io/api/core/v1"
1816 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"
2217 "sigs.k8s.io/controller-runtime/pkg/client"
2318
2419 helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
@@ -28,10 +23,7 @@ import (
2823 "github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
2924 "github.com/operator-framework/operator-controller/internal/operator-controller/contentmanager"
3025 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"
3326 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
34- "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
3527)
3628
3729var _ contentmanager.Manager = (* mockManagedContentCacheManager )(nil )
@@ -246,8 +238,8 @@ func TestApply_Base(t *testing.T) {
246238 t .Run ("fails trying to obtain an action client" , func (t * testing.T ) {
247239 mockAcg := & mockActionGetter {actionClientForErr : errors .New ("failed getting action client" )}
248240 helmApplier := applier.Helm {
249- ActionClientGetter : mockAcg ,
250- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
241+ ActionClientGetter : mockAcg ,
242+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
251243 }
252244
253245 installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -260,8 +252,8 @@ func TestApply_Base(t *testing.T) {
260252 t .Run ("fails getting current release and !driver.ErrReleaseNotFound" , func (t * testing.T ) {
261253 mockAcg := & mockActionGetter {getClientErr : errors .New ("failed getting current release" )}
262254 helmApplier := applier.Helm {
263- ActionClientGetter : mockAcg ,
264- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
255+ ActionClientGetter : mockAcg ,
256+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
265257 }
266258
267259 installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -279,8 +271,8 @@ func TestApply_Installation(t *testing.T) {
279271 dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
280272 }
281273 helmApplier := applier.Helm {
282- ActionClientGetter : mockAcg ,
283- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
274+ ActionClientGetter : mockAcg ,
275+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
284276 }
285277
286278 installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -299,7 +291,7 @@ func TestApply_Installation(t *testing.T) {
299291 helmApplier := applier.Helm {
300292 ActionClientGetter : mockAcg ,
301293 Preflights : []applier.Preflight {mockPf },
302- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
294+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
303295 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
304296 }
305297
@@ -317,7 +309,7 @@ func TestApply_Installation(t *testing.T) {
317309 }
318310 helmApplier := applier.Helm {
319311 ActionClientGetter : mockAcg ,
320- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
312+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
321313 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
322314 }
323315
@@ -338,7 +330,7 @@ func TestApply_Installation(t *testing.T) {
338330 }
339331 helmApplier := applier.Helm {
340332 ActionClientGetter : mockAcg ,
341- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
333+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
342334 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
343335 Manager : & mockManagedContentCacheManager {
344336 cache : & mockManagedContentCache {},
@@ -359,8 +351,8 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
359351 dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
360352 }
361353 helmApplier := applier.Helm {
362- ActionClientGetter : mockAcg ,
363- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
354+ ActionClientGetter : mockAcg ,
355+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
364356 }
365357
366358 installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -384,7 +376,7 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
384376 ActionClientGetter : mockAcg ,
385377 Preflights : []applier.Preflight {mockPf },
386378 PreAuthorizer : & mockPreAuthorizer {nil , nil },
387- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
379+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
388380 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
389381 }
390382
@@ -404,9 +396,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
404396 },
405397 }
406398 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 {},
410402 }
411403 // Use a ClusterExtension with valid Spec fields.
412404 validCE := & ocv1.ClusterExtension {
@@ -433,9 +425,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
433425 },
434426 }
435427 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 {},
439431 }
440432 // Use a ClusterExtension with valid Spec fields.
441433 validCE := & ocv1.ClusterExtension {
@@ -464,7 +456,7 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
464456 helmApplier := applier.Helm {
465457 ActionClientGetter : mockAcg ,
466458 PreAuthorizer : & mockPreAuthorizer {nil , nil },
467- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
459+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
468460 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
469461 Manager : & mockManagedContentCacheManager {
470462 cache : & mockManagedContentCache {},
@@ -498,8 +490,8 @@ func TestApply_Upgrade(t *testing.T) {
498490 dryRunUpgradeErr : errors .New ("failed attempting to dry-run upgrade chart" ),
499491 }
500492 helmApplier := applier.Helm {
501- ActionClientGetter : mockAcg ,
502- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
493+ ActionClientGetter : mockAcg ,
494+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
503495 }
504496
505497 installSucceeded , installStatus , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -522,7 +514,7 @@ func TestApply_Upgrade(t *testing.T) {
522514 helmApplier := applier.Helm {
523515 ActionClientGetter : mockAcg ,
524516 Preflights : []applier.Preflight {mockPf },
525- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
517+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
526518 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
527519 }
528520
@@ -545,7 +537,7 @@ func TestApply_Upgrade(t *testing.T) {
545537 mockPf := & mockPreflight {}
546538 helmApplier := applier.Helm {
547539 ActionClientGetter : mockAcg , Preflights : []applier.Preflight {mockPf },
548- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
540+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
549541 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
550542 }
551543
@@ -569,7 +561,7 @@ func TestApply_Upgrade(t *testing.T) {
569561 helmApplier := applier.Helm {
570562 ActionClientGetter : mockAcg ,
571563 Preflights : []applier.Preflight {mockPf },
572- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
564+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
573565 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
574566 }
575567
@@ -590,7 +582,7 @@ func TestApply_Upgrade(t *testing.T) {
590582 }
591583 helmApplier := applier.Helm {
592584 ActionClientGetter : mockAcg ,
593- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {},
585+ HelmChartProvider : & applier. RegistryV1HelmChartProvider {},
594586 HelmReleaseToObjectsConverter : mockHelmReleaseToObjectsConverter {},
595587 Manager : & mockManagedContentCacheManager {
596588 cache : & mockManagedContentCache {},
@@ -604,53 +596,8 @@ func TestApply_Upgrade(t *testing.T) {
604596 })
605597}
606598
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-
650599func TestApply_RegistryV1ToChartConverterIntegration (t * testing.T ) {
651600 t .Run ("generates bundle resources in AllNamespaces install mode" , func (t * testing.T ) {
652- var expectedWatchNamespace = corev1 .NamespaceAll
653-
654601 helmApplier := applier.Helm {
655602 ActionClientGetter : & mockActionGetter {
656603 getClientErr : driver .ErrReleaseNotFound ,
@@ -659,9 +606,9 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
659606 Manifest : validManifest ,
660607 },
661608 },
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 )
665612 return nil , nil
666613 },
667614 },
@@ -683,8 +630,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
683630 Manifest : validManifest ,
684631 },
685632 },
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 ) {
688635 return nil , errors .New ("some error" )
689636 },
690637 },
@@ -698,10 +645,10 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
698645 })
699646}
700647
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 )
703650}
704651
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 )
707654}
0 commit comments