github.com/ironcore-dev/gardener-extension-provider-ironcore@v0.3.2-0.20240314231816-8336447fb9a0/pkg/controller/bastion/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 bastion
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/gardener/gardener/extensions/pkg/controller/bastion"
    10  	"sigs.k8s.io/controller-runtime/pkg/controller"
    11  	"sigs.k8s.io/controller-runtime/pkg/log"
    12  	"sigs.k8s.io/controller-runtime/pkg/manager"
    13  
    14  	controllerconfig "github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/apis/config"
    15  	"github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/ironcore"
    16  )
    17  
    18  var (
    19  	// DefaultAddOptions are the default AddOptions for AddToManager.
    20  	DefaultAddOptions = AddOptions{}
    21  )
    22  
    23  // AddOptions are options to apply when adding the ironcore bastion controller to the manager.
    24  type AddOptions struct {
    25  	// Controller are the controller.Options.
    26  	Controller controller.Options
    27  	// IgnoreOperationAnnotation specifies whether to ignore the operation annotation or not.
    28  	IgnoreOperationAnnotation bool
    29  	// BastionConfig contains config for the Bastion config.
    30  	BastionConfig controllerconfig.BastionConfig
    31  }
    32  
    33  // AddToManagerWithOptions adds a controller with the given AddOptions to the given manager.
    34  // The opts.Reconciler is being set with a newly instantiated actuator.
    35  func AddToManagerWithOptions(mgr manager.Manager, opts AddOptions) error {
    36  	return bastion.Add(mgr, bastion.AddArgs{
    37  		Actuator:          NewActuator(mgr, &opts.BastionConfig),
    38  		ConfigValidator:   NewConfigValidator(mgr.GetClient(), log.Log),
    39  		ControllerOptions: opts.Controller,
    40  		Predicates:        bastion.DefaultPredicates(opts.IgnoreOperationAnnotation),
    41  		Type:              ironcore.Type,
    42  	})
    43  }
    44  
    45  // AddToManager adds a controller with the default AddOptions.
    46  func AddToManager(_ context.Context, mgr manager.Manager) error {
    47  	return AddToManagerWithOptions(mgr, DefaultAddOptions)
    48  }