Skip to content

Commit

Permalink
Spell out Options
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Godding Boye <[email protected]>
  • Loading branch information
erikgb committed Nov 23, 2024
1 parent 35b7156 commit 4e6bd3c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions pkg/bundle/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/bundle/internal/target/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand Down

0 comments on commit 4e6bd3c

Please sign in to comment.