diff --git a/pkg/bundle/bundle.go b/pkg/bundle/bundle.go index 711f14c5..20a208a1 100644 --- a/pkg/bundle/bundle.go +++ b/pkg/bundle/bundle.go @@ -52,8 +52,8 @@ type bundle struct { // clock returns time which can be overwritten for testing. clock clock.Clock - // Bundle holds options for the Bundle controller. - Opts options.Bundle + // Options holds options for the Bundle controller. + Options options.Bundle sources *target.BundleBuilder @@ -82,7 +82,7 @@ func (b *bundle) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, } func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (result ctrl.Result, statusPatch *trustapi.BundleStatus, returnedErr error) { - log := b.Opts.Log.WithValues("bundle", req.NamespacedName.Name) + log := b.Options.Log.WithValues("bundle", req.NamespacedName.Name) log.V(2).Info("syncing bundle") var bundle trustapi.Bundle @@ -140,7 +140,7 @@ func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (result } // Detect if we have a bundle with Secret targets but the feature is disabled. - if !b.Opts.SecretTargetsEnabled && bundle.Spec.Target.Secret != nil { + if !b.Options.SecretTargetsEnabled && bundle.Spec.Target.Secret != nil { log.Error(err, "bundle has Secret targets but the feature is disabled") b.recorder.Eventf(&bundle, corev1.EventTypeWarning, "SecretTargetsDisabled", "Bundle has Secret targets but the feature is disabled") @@ -203,7 +203,7 @@ func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (result // Find all old existing target resources. targetKinds := []target.Kind{target.KindConfigMap} - if b.Opts.SecretTargetsEnabled { + if b.Options.SecretTargetsEnabled { targetKinds = append(targetKinds, target.KindSecret) } for _, kind := range targetKinds { diff --git a/pkg/bundle/bundle_test.go b/pkg/bundle/bundle_test.go index 205f0b26..ef15a26a 100644 --- a/pkg/bundle/bundle_test.go +++ b/pkg/bundle/bundle_test.go @@ -1454,10 +1454,10 @@ func Test_Reconcile(t *testing.T) { client: fakeClient, recorder: fakeRecorder, clock: fixedclock, - Opts: opts, + Options: opts, sources: &target.BundleBuilder{ - Client: fakeClient, - Opts: opts, + Client: fakeClient, + Options: opts, }, targetReconciler: &target.Reconciler{ Client: fakeClient, diff --git a/pkg/bundle/controller.go b/pkg/bundle/controller.go index fe8c76f2..25b82607 100644 --- a/pkg/bundle/controller.go +++ b/pkg/bundle/controller.go @@ -53,8 +53,8 @@ func AddBundleController( targetCache cache.Cache, ) error { sourceBuilder := &target.BundleBuilder{ - Client: mgr.GetClient(), - Opts: opts, + Client: mgr.GetClient(), + Options: opts, } if err := sourceBuilder.Init(); err != nil { return err @@ -64,7 +64,7 @@ func AddBundleController( client: mgr.GetClient(), recorder: mgr.GetEventRecorderFor("bundles"), clock: clock.RealClock{}, - Opts: opts, + Options: opts, sources: sourceBuilder, targetReconciler: &target.Reconciler{ Client: mgr.GetClient(), @@ -138,7 +138,7 @@ func AddBundleController( } } return false - }), builder.WithPredicates(inNamespacePredicate(b.Opts.Namespace))). + }), builder.WithPredicates(inNamespacePredicate(b.Options.Namespace))). // Watch Secrets in trust Namespace. // Reconcile Bundles who reference a modified source Secret. @@ -150,7 +150,7 @@ func AddBundleController( } } return false - }), builder.WithPredicates(inNamespacePredicate(b.Opts.Namespace))) + }), builder.WithPredicates(inNamespacePredicate(b.Options.Namespace))) // Complete controller. if err := controller.Complete(b); err != nil { @@ -189,7 +189,7 @@ func (b *bundle) enqueueRequestsFromBundleFunc(fn func(obj client.Object, bundle func (b *bundle) mustBundleList(ctx context.Context) *trustapi.BundleList { var bundleList trustapi.BundleList if err := b.client.List(ctx, &bundleList); err != nil { - b.Opts.Log.Error(err, "failed to list all Bundles, exiting error") + b.Options.Log.Error(err, "failed to list all Bundles, exiting error") os.Exit(-1) } diff --git a/pkg/bundle/internal/target/source.go b/pkg/bundle/internal/target/source.go index c806a11f..ff36ebbe 100644 --- a/pkg/bundle/internal/target/source.go +++ b/pkg/bundle/internal/target/source.go @@ -56,20 +56,20 @@ type BundleBuilder struct { // at startup. DefaultPackage *fspkg.Package - // Opts holds options for the Bundle controller. - Opts options.Bundle + // Options holds options for the Bundle controller. + Options options.Bundle } func (b *BundleBuilder) Init() error { - if b.Opts.DefaultPackageLocation != "" { - pkg, err := fspkg.LoadPackageFromFile(b.Opts.DefaultPackageLocation) + if b.Options.DefaultPackageLocation != "" { + pkg, err := fspkg.LoadPackageFromFile(b.Options.DefaultPackageLocation) if err != nil { return fmt.Errorf("must load default package successfully when default package location is set: %w", err) } b.DefaultPackage = &pkg - b.Opts.Log.Info("successfully loaded default package from filesystem", "path", b.Opts.DefaultPackageLocation) + b.Options.Log.Info("successfully loaded default package from filesystem", "path", b.Options.DefaultPackageLocation) } return nil @@ -80,7 +80,7 @@ func (b *BundleBuilder) Init() error { // is each bundle is concatenated together with a new line character. func (b *BundleBuilder) BuildBundle(ctx context.Context, sources []trustapi.BundleSource, formats *trustapi.AdditionalFormats) (BundleData, error) { var resolvedBundle BundleData - certPool := util.NewCertPool(util.WithFilteredExpiredCerts(b.Opts.FilterExpiredCerts)) + certPool := util.NewCertPool(util.WithFilteredExpiredCerts(b.Options.FilterExpiredCerts)) for _, source := range sources { var ( @@ -113,7 +113,7 @@ func (b *BundleBuilder) BuildBundle(ctx context.Context, sources []trustapi.Bund // A source selector may select no configmaps/secrets, and this is not an error. if errors.As(err, &selectsNothingError{}) { - b.Opts.Log.Info(err.Error()) + b.Options.Log.Info(err.Error()) continue } @@ -148,12 +148,12 @@ func (b *BundleBuilder) configMapBundle(ctx context.Context, ref *trustapi.Sourc if ref.Name != "" { cm := corev1.ConfigMap{} if err := b.Client.Get(ctx, client.ObjectKey{ - Namespace: b.Opts.Namespace, + Namespace: b.Options.Namespace, Name: ref.Name, }, &cm); apierrors.IsNotFound(err) { return "", SourceNotFoundError{err} } else if err != nil { - return "", fmt.Errorf("failed to get ConfigMap %s/%s: %w", b.Opts.Namespace, ref.Name, err) + return "", fmt.Errorf("failed to get ConfigMap %s/%s: %w", b.Options.Namespace, ref.Name, err) } configMaps = []corev1.ConfigMap{cm} @@ -162,7 +162,7 @@ func (b *BundleBuilder) configMapBundle(ctx context.Context, ref *trustapi.Sourc cml := corev1.ConfigMapList{} selector, selectorErr := metav1.LabelSelectorAsSelector(ref.Selector) if selectorErr != nil { - return "", fmt.Errorf("failed to parse label selector as Selector for ConfigMap in namespace %s: %w", b.Opts.Namespace, selectorErr) + return "", fmt.Errorf("failed to parse label selector as Selector for ConfigMap in namespace %s: %w", b.Options.Namespace, selectorErr) } if err := b.Client.List(ctx, &cml, client.MatchingLabelsSelector{Selector: selector}); err != nil { return "", fmt.Errorf("failed to get ConfigMapList: %w", err) @@ -202,12 +202,12 @@ func (b *BundleBuilder) secretBundle(ctx context.Context, ref *trustapi.SourceOb if ref.Name != "" { s := corev1.Secret{} if err := b.Client.Get(ctx, client.ObjectKey{ - Namespace: b.Opts.Namespace, + Namespace: b.Options.Namespace, Name: ref.Name, }, &s); apierrors.IsNotFound(err) { return "", SourceNotFoundError{err} } else if err != nil { - return "", fmt.Errorf("failed to get Secret %s/%s: %w", b.Opts.Namespace, ref.Name, err) + return "", fmt.Errorf("failed to get Secret %s/%s: %w", b.Options.Namespace, ref.Name, err) } secrets = []corev1.Secret{s} @@ -216,7 +216,7 @@ func (b *BundleBuilder) secretBundle(ctx context.Context, ref *trustapi.SourceOb sl := corev1.SecretList{} selector, selectorErr := metav1.LabelSelectorAsSelector(ref.Selector) if selectorErr != nil { - return "", fmt.Errorf("failed to parse label selector as Selector for Secret in namespace %s: %w", b.Opts.Namespace, selectorErr) + return "", fmt.Errorf("failed to parse label selector as Selector for Secret in namespace %s: %w", b.Options.Namespace, selectorErr) } if err := b.Client.List(ctx, &sl, client.MatchingLabelsSelector{Selector: selector}); err != nil { return "", fmt.Errorf("failed to get SecretList: %w", err)