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

     1  // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package controlplane
     5  
     6  import (
     7  	"context"
     8  
     9  	extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
    10  	"github.com/gardener/gardener/extensions/pkg/controller/controlplane"
    11  	"github.com/gardener/gardener/extensions/pkg/controller/controlplane/genericactuator"
    12  	"github.com/gardener/gardener/extensions/pkg/util"
    13  	"sigs.k8s.io/controller-runtime/pkg/controller"
    14  	"sigs.k8s.io/controller-runtime/pkg/manager"
    15  
    16  	"github.com/ironcore-dev/gardener-extension-provider-ironcore/imagevector"
    17  	"github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/ironcore"
    18  )
    19  
    20  var (
    21  	// DefaultAddOptions are the default AddOptions for AddToManager.
    22  	DefaultAddOptions = AddOptions{}
    23  )
    24  
    25  // AddOptions are options to apply when adding the ironcore controlplane controller to the manager.
    26  type AddOptions struct {
    27  	// Controller are the controller.Options.
    28  	Controller controller.Options
    29  	// IgnoreOperationAnnotation specifies whether to ignore the operation annotation or not.
    30  	IgnoreOperationAnnotation bool
    31  	// WebhookServerNamespace is the namespace in which the webhook server runs.
    32  	WebhookServerNamespace string
    33  }
    34  
    35  // AddToManagerWithOptions adds a controller with the given Options to the given manager.
    36  // The opts.Reconciler is being set with a newly instantiated actuator.
    37  func AddToManagerWithOptions(ctx context.Context, mgr manager.Manager, opts AddOptions) error {
    38  	genericActuator, err := genericactuator.NewActuator(mgr,
    39  		ironcore.ProviderName,
    40  		secretConfigsFunc,
    41  		shootAccessSecretsFunc,
    42  		nil,
    43  		nil,
    44  		configChart,
    45  		controlPlaneChart,
    46  		controlPlaneShootChart,
    47  		nil,
    48  		storageClassChart,
    49  		nil,
    50  		NewValuesProvider(mgr),
    51  		extensionscontroller.ChartRendererFactoryFunc(util.NewChartRendererForShoot),
    52  		imagevector.ImageVector(),
    53  		ironcore.CloudProviderConfigName,
    54  		nil,
    55  		opts.WebhookServerNamespace)
    56  
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	return controlplane.Add(ctx, mgr, controlplane.AddArgs{
    62  		Actuator:          genericActuator,
    63  		ControllerOptions: opts.Controller,
    64  		Predicates:        controlplane.DefaultPredicates(ctx, mgr, opts.IgnoreOperationAnnotation),
    65  		Type:              ironcore.Type,
    66  	})
    67  }
    68  
    69  // AddToManager adds a controller with the default Options.
    70  func AddToManager(ctx context.Context, mgr manager.Manager) error {
    71  	return AddToManagerWithOptions(ctx, mgr, DefaultAddOptions)
    72  }