github.com/ironcore-dev/gardener-extension-provider-ironcore@v0.3.2-0.20240314231816-8336447fb9a0/pkg/controller/backupentry/add.go (about)

     1  // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package backupentry
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/gardener/gardener/extensions/pkg/controller/backupentry"
    10  	"github.com/gardener/gardener/extensions/pkg/controller/backupentry/genericactuator"
    11  	"sigs.k8s.io/controller-runtime/pkg/controller"
    12  	"sigs.k8s.io/controller-runtime/pkg/manager"
    13  
    14  	"github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/ironcore"
    15  )
    16  
    17  var (
    18  	// DefaultAddOptions are the default AddOptions for AddToManager.
    19  	DefaultAddOptions = AddOptions{}
    20  )
    21  
    22  // AddOptions are options to apply when adding the ironcore backupentry controller to the manager.
    23  type AddOptions struct {
    24  	// Controller are the controller.Options.
    25  	Controller controller.Options
    26  	// IgnoreOperationAnnotation specifies whether to ignore the operation annotation or not.
    27  	IgnoreOperationAnnotation bool
    28  }
    29  
    30  // AddToManagerWithOptions adds a controller with the given Options to the given manager.
    31  // The opts.Reconciler is being set with a newly instantiated actuator.
    32  func AddToManagerWithOptions(ctx context.Context, mgr manager.Manager, opts AddOptions) error {
    33  	return backupentry.Add(ctx, mgr, backupentry.AddArgs{
    34  		Actuator:          genericactuator.NewActuator(mgr, newActuator(mgr)),
    35  		ControllerOptions: opts.Controller,
    36  		Predicates:        backupentry.DefaultPredicates(opts.IgnoreOperationAnnotation),
    37  		Type:              ironcore.Type,
    38  	})
    39  }
    40  
    41  // AddToManager adds a controller with the default Options.
    42  func AddToManager(ctx context.Context, mgr manager.Manager) error {
    43  	return AddToManagerWithOptions(ctx, mgr, DefaultAddOptions)
    44  }