4
4
"context"
5
5
"errors"
6
6
"io"
7
- "io/fs"
8
7
"os"
9
8
"testing"
10
9
"testing/fstest"
@@ -27,6 +26,7 @@ import (
27
26
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
28
27
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
29
28
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
29
+ "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
30
30
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
31
31
)
32
32
@@ -197,8 +197,8 @@ func TestApply_Base(t *testing.T) {
197
197
t .Run ("fails trying to obtain an action client" , func (t * testing.T ) {
198
198
mockAcg := & mockActionGetter {actionClientForErr : errors .New ("failed getting action client" )}
199
199
helmApplier := applier.Helm {
200
- ActionClientGetter : mockAcg ,
201
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
200
+ ActionClientGetter : mockAcg ,
201
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
202
202
}
203
203
204
204
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -211,8 +211,8 @@ func TestApply_Base(t *testing.T) {
211
211
t .Run ("fails getting current release and !driver.ErrReleaseNotFound" , func (t * testing.T ) {
212
212
mockAcg := & mockActionGetter {getClientErr : errors .New ("failed getting current release" )}
213
213
helmApplier := applier.Helm {
214
- ActionClientGetter : mockAcg ,
215
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
214
+ ActionClientGetter : mockAcg ,
215
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
216
216
}
217
217
218
218
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -230,8 +230,8 @@ func TestApply_Installation(t *testing.T) {
230
230
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
231
231
}
232
232
helmApplier := applier.Helm {
233
- ActionClientGetter : mockAcg ,
234
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
233
+ ActionClientGetter : mockAcg ,
234
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
235
235
}
236
236
237
237
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -248,9 +248,9 @@ func TestApply_Installation(t *testing.T) {
248
248
}
249
249
mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
250
250
helmApplier := applier.Helm {
251
- ActionClientGetter : mockAcg ,
252
- Preflights : []applier.Preflight {mockPf },
253
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
251
+ ActionClientGetter : mockAcg ,
252
+ Preflights : []applier.Preflight {mockPf },
253
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
254
254
}
255
255
256
256
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -266,8 +266,8 @@ func TestApply_Installation(t *testing.T) {
266
266
installErr : errors .New ("failed installing chart" ),
267
267
}
268
268
helmApplier := applier.Helm {
269
- ActionClientGetter : mockAcg ,
270
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
269
+ ActionClientGetter : mockAcg ,
270
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
271
271
}
272
272
273
273
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -286,8 +286,8 @@ func TestApply_Installation(t *testing.T) {
286
286
},
287
287
}
288
288
helmApplier := applier.Helm {
289
- ActionClientGetter : mockAcg ,
290
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
289
+ ActionClientGetter : mockAcg ,
290
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
291
291
}
292
292
293
293
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -306,8 +306,8 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
306
306
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
307
307
}
308
308
helmApplier := applier.Helm {
309
- ActionClientGetter : mockAcg ,
310
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
309
+ ActionClientGetter : mockAcg ,
310
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
311
311
}
312
312
313
313
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -328,10 +328,10 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
328
328
}
329
329
mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
330
330
helmApplier := applier.Helm {
331
- ActionClientGetter : mockAcg ,
332
- Preflights : []applier.Preflight {mockPf },
333
- PreAuthorizer : & mockPreAuthorizer {nil , nil },
334
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
331
+ ActionClientGetter : mockAcg ,
332
+ Preflights : []applier.Preflight {mockPf },
333
+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
334
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
335
335
}
336
336
337
337
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -350,9 +350,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
350
350
},
351
351
}
352
352
helmApplier := applier.Helm {
353
- ActionClientGetter : mockAcg ,
354
- PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
355
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
353
+ ActionClientGetter : mockAcg ,
354
+ PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
355
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
356
356
}
357
357
// Use a ClusterExtension with valid Spec fields.
358
358
validCE := & ocv1.ClusterExtension {
@@ -379,9 +379,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
379
379
},
380
380
}
381
381
helmApplier := applier.Helm {
382
- ActionClientGetter : mockAcg ,
383
- PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
384
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
382
+ ActionClientGetter : mockAcg ,
383
+ PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
384
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
385
385
}
386
386
// Use a ClusterExtension with valid Spec fields.
387
387
validCE := & ocv1.ClusterExtension {
@@ -408,9 +408,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
408
408
},
409
409
}
410
410
helmApplier := applier.Helm {
411
- ActionClientGetter : mockAcg ,
412
- PreAuthorizer : & mockPreAuthorizer {nil , nil },
413
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
411
+ ActionClientGetter : mockAcg ,
412
+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
413
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
414
414
}
415
415
416
416
// Use a ClusterExtension with valid Spec fields.
@@ -442,8 +442,8 @@ func TestApply_Upgrade(t *testing.T) {
442
442
dryRunUpgradeErr : errors .New ("failed attempting to dry-run upgrade chart" ),
443
443
}
444
444
helmApplier := applier.Helm {
445
- ActionClientGetter : mockAcg ,
446
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
445
+ ActionClientGetter : mockAcg ,
446
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
447
447
}
448
448
449
449
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -464,9 +464,9 @@ func TestApply_Upgrade(t *testing.T) {
464
464
}
465
465
mockPf := & mockPreflight {upgradeErr : errors .New ("failed during upgrade pre-flight check" )}
466
466
helmApplier := applier.Helm {
467
- ActionClientGetter : mockAcg ,
468
- Preflights : []applier.Preflight {mockPf },
469
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
467
+ ActionClientGetter : mockAcg ,
468
+ Preflights : []applier.Preflight {mockPf },
469
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
470
470
}
471
471
472
472
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -488,7 +488,7 @@ func TestApply_Upgrade(t *testing.T) {
488
488
mockPf := & mockPreflight {}
489
489
helmApplier := applier.Helm {
490
490
ActionClientGetter : mockAcg , Preflights : []applier.Preflight {mockPf },
491
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
491
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
492
492
}
493
493
494
494
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -509,9 +509,9 @@ func TestApply_Upgrade(t *testing.T) {
509
509
}
510
510
mockPf := & mockPreflight {}
511
511
helmApplier := applier.Helm {
512
- ActionClientGetter : mockAcg ,
513
- Preflights : []applier.Preflight {mockPf },
514
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
512
+ ActionClientGetter : mockAcg ,
513
+ Preflights : []applier.Preflight {mockPf },
514
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
515
515
}
516
516
517
517
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -530,8 +530,8 @@ func TestApply_Upgrade(t *testing.T) {
530
530
desiredRel : & testDesiredRelease ,
531
531
}
532
532
helmApplier := applier.Helm {
533
- ActionClientGetter : mockAcg ,
534
- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
533
+ ActionClientGetter : mockAcg ,
534
+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
535
535
}
536
536
537
537
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -556,9 +556,11 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
556
556
Manifest : validManifest ,
557
557
},
558
558
},
559
- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
560
- require .Equal (t , expectedWatchNamespace , watchNamespace )
561
- return convert .RegistryV1ToHelmChart (rv1 , installNamespace , watchNamespace )
559
+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
560
+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
561
+ require .Equal (t , expectedWatchNamespace , watchNamespace )
562
+ return nil , nil
563
+ },
562
564
},
563
565
}
564
566
@@ -587,9 +589,11 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
587
589
Manifest : validManifest ,
588
590
},
589
591
},
590
- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
591
- require .Equal (t , expectedWatchNamespace , watchNamespace )
592
- return convert .RegistryV1ToHelmChart (rv1 , installNamespace , watchNamespace )
592
+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
593
+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
594
+ require .Equal (t , expectedWatchNamespace , watchNamespace )
595
+ return nil , nil
596
+ },
593
597
},
594
598
}
595
599
@@ -605,12 +609,22 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
605
609
Manifest : validManifest ,
606
610
},
607
611
},
608
- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
609
- return nil , errors .New ("some error" )
612
+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
613
+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
614
+ return nil , errors .New ("some error" )
615
+ },
610
616
},
611
617
}
612
618
613
619
_ , _ , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
614
620
require .Error (t , err )
615
621
})
616
622
}
623
+
624
+ type fakeBundleToHelmChartConverter struct {
625
+ fn func (source.BundleSource , string , string ) (* chart.Chart , error )
626
+ }
627
+
628
+ func (f fakeBundleToHelmChartConverter ) ToHelmChart (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
629
+ return f .fn (bundle , installNamespace , watchNamespace )
630
+ }
0 commit comments