reconciler

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 37 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerSetup added in v0.1.0

type ControllerSetup interface {
	// Watch takes events provided by a Source and uses the EventHandler to
	// enqueue reconcile.Requests in response to the events.
	//
	// Watch may be provided one or more Predicates to filter events before
	// they are given to the EventHandler.  Events will be passed to the
	// EventHandler if all provided Predicates evaluate to true.
	Watch(src source.Source, eventhandler handler.EventHandler, predicates ...predicate.Predicate) error
}

ControllerSetup allows restricted access to the Controller using the WithControllerSetupFunc option. Currently the only supposed configuration is adding additional watchers do the controller.

type ControllerSetupFunc added in v0.1.0

type ControllerSetupFunc func(c ControllerSetup) error

ControllerSetupFunc allows configuring a controller's builder.

type Option

type Option func(r *Reconciler) error

Option is a function that configures the helm Reconciler.

func SkipDependentWatches

func SkipDependentWatches(skip bool) Option

WithDependentWatchesEnabled is an Option that configures whether the Reconciler will register watches for dependent objects in releases and trigger reconciliations when they change.

By default, dependent watches are enabled.

func SkipPrimaryGVKSchemeRegistration added in v0.0.10

func SkipPrimaryGVKSchemeRegistration(skip bool) Option

SkipPrimaryGVKSchemeRegistration is an Option that allows to disable the default behaviour of registering unstructured.Unstructured as underlying type for the GVK scheme.

Disabling this built-in registration is necessary when building operators for which it is desired to have the underlying GVK scheme backed by a custom struct type.

Example for using a custom type for the GVK scheme instead of unstructured.Unstructured:

// Define custom type for GVK scheme.
//+kubebuilder:object:root=true
type Custom struct {
  // [...]
}

// Register custom type along with common meta types in scheme.
scheme := runtime.NewScheme()
scheme.AddKnownTypes(SchemeGroupVersion, &Custom{})
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

// Create new manager using the controller-runtime, injecting above scheme.
options := ctrl.Options{
  Scheme = scheme,
  // [...]
}
mgr, err := ctrl.NewManager(config, options)

// Create reconciler with generic scheme registration being disabled.
r, err := reconciler.New(
  reconciler.WithChart(chart),
  reconciler.SkipPrimaryGVKSchemeRegistration(true),
  // [...]
)

// Setup reconciler with above manager.
err = r.SetupWithManager(mgr)

By default, skipping of the generic scheme setup is disabled, which means that unstructured.Unstructured is used for the GVK scheme.

func WithActionClientGetter

func WithActionClientGetter(actionClientGetter helmclient.ActionClientGetter) Option

WithActionClientGetter is an Option that configures a Reconciler's ActionClientGetter.

A default ActionClientGetter is used if this option is not configured.

func WithChart

func WithChart(chrt chart.Chart) Option

WithChart is an Option that configures a Reconciler's helm chart.

This option is required.

func WithClient

func WithClient(cl client.Client) Option

WithClient is an Option that configures a Reconciler's client.

By default, manager.GetClient() is used if this option is not configured.

func WithControllerSetupFunc added in v0.1.0

func WithControllerSetupFunc(f ControllerSetupFunc) Option

WithControllerSetupFunc is an Option that allows customizing a controller before it is started. The only supported customization here is adding additional Watch sources to the controller.

func WithEventRecorder

func WithEventRecorder(er record.EventRecorder) Option

WithEventRecorder is an Option that configures a Reconciler's EventRecorder.

By default, manager.GetEventRecorderFor() is used if this option is not configured.

func WithGroupVersionKind

func WithGroupVersionKind(gvk schema.GroupVersionKind) Option

WithGroupVersionKind is an Option that configures a Reconciler's GroupVersionKind.

This option is required.

func WithInstallAnnotations

func WithInstallAnnotations(as ...annotation.Install) Option

WithInstallAnnotations is an Option that configures Install annotations to enable custom action.Install fields to be set based on the value of annotations found in the custom resource watched by this reconciler. Duplicate annotation names will result in an error.

func WithLog

func WithLog(log logr.Logger) Option

WithLog is an Option that configures a Reconciler's logger.

A default logger is used if this option is not configured.

func WithMaxConcurrentReconciles

func WithMaxConcurrentReconciles(max int) Option

WithMaxConcurrentReconciles is an Option that configures the number of concurrent reconciles that the controller will run.

The default is 1.

func WithMaxReleaseHistory added in v0.0.9

func WithMaxReleaseHistory(maxHistory int) Option

WithMaxReleaseHistory specifies the maximum size of the Helm release history maintained on upgrades/rollbacks. Zero (default) means unlimited.

func WithOverrideValues

func WithOverrideValues(overrides map[string]string) Option

WithOverrideValues is an Option that configures a Reconciler's override values.

Override values can be used to enforce that certain values provided by the chart's default values.yaml or by a CR spec are always overridden when rendering the chart. If a value in overrides is set by a CR, it is overridden by the override value. The override value can be static but can also refer to an environment variable.

If an environment variable reference is listed in override values but is not present in the environment when this function runs, it will resolve to an empty string and override all other values. Therefore, when using environment variable expansion, ensure that the environment variable is set.

func WithPostHook

func WithPostHook(h hook.PostHook) Option

WithPostHook is an Option that configures the reconciler to run the given PostHook just after performing any non-uninstall release actions.

func WithPreHook

func WithPreHook(h hook.PreHook) Option

WithPreHook is an Option that configures the reconciler to run the given PreHook just before performing any actions (e.g. install, upgrade, uninstall, or reconciliation).

func WithReconcilePeriod

func WithReconcilePeriod(rp time.Duration) Option

WithReconcilePeriod is an Option that configures the reconcile period of the controller. This will cause the controller to reconcile CRs at least once every period. By default, the reconcile period is set to 0, which means no time-based reconciliations will occur.

func WithSelector added in v0.0.9

func WithSelector(s metav1.LabelSelector) Option

WithSelector is an Option that configures the reconciler to creates a predicate that is used to filter resources based on the specified selector

func WithUninstallAnnotations

func WithUninstallAnnotations(as ...annotation.Uninstall) Option

WithUninstallAnnotations is an Option that configures Uninstall annotations to enable custom action.Uninstall fields to be set based on the value of annotations found in the custom resource watched by this reconciler. Duplicate annotation names will result in an error.

func WithUpgradeAnnotations

func WithUpgradeAnnotations(as ...annotation.Upgrade) Option

WithUpgradeAnnotations is an Option that configures Upgrade annotations to enable custom action.Upgrade fields to be set based on the value of annotations found in the custom resource watched by this reconciler. Duplicate annotation names will result in an error.

func WithValueMapper deprecated

func WithValueMapper(m values.Mapper) Option

WithValueMapper is an Option that configures a function that maps values from a custom resource spec to the values passed to Helm. Use this if you want to apply a transformation on the values obtained from your custom resource, before they are passed to Helm.

Deprecated: Use WithValueTranslator instead. WithValueMapper will be removed in a future release.

func WithValueTranslator added in v0.0.9

func WithValueTranslator(t values.Translator) Option

WithValueTranslator is an Option that configures a function that translates a custom resource to the values passed to Helm. Use this if you need to customize the logic that translates your custom resource to Helm values. If you wish to, you can convert the Unstructured that is passed to your Translator to your own Custom Resource struct like this:

import "k8s.io/apimachinery/pkg/runtime"
foo := your.Foo{}
if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &foo); err != nil {
  return nil, err
}
// work with the type-safe foo

Alternatively, your translator can also work similarly to a Mapper, by accessing the spec with:

u.Object["spec"].(map[string]interface{})

type Reconciler

type Reconciler struct {
	// contains filtered or unexported fields
}

Reconciler reconciles a Helm object

func New

func New(opts ...Option) (*Reconciler, error)

New creates a new Reconciler that reconciles custom resources that define a Helm release. New takes variadic Option arguments that are used to configure the Reconciler.

Required options are:

  • WithGroupVersionKind
  • WithChart

Other options are defaulted to sane defaults when SetupWithManager is called.

If an error occurs configuring or validating the Reconciler, it is returned.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile reconciles a CR that defines a Helm v3 release.

  • If a release does not exist for this CR, a new release is installed.
  • If a release exists and the CR spec has changed since the last, reconciliation, the release is upgraded.
  • If a release exists and the CR spec has not changed since the last reconciliation, the release is reconciled. Any dependent resources that have diverged from the release manifest are re-created or patched so that they are re-aligned with the release.
  • If the CR has been deleted, the release will be uninstalled. The Reconciler uses a finalizer to ensure the release uninstall succeeds before CR deletion occurs.

If an error occurs during release installation or upgrade, the change will be rolled back to restore the previous state.

Reconcile also manages the status field of the custom resource. It includes the release name and manifest in `status.deployedRelease`, and it updates `status.conditions` based on reconciliation progress and success. Condition types include:

  • Deployed - a release for this CR is deployed (but not necessarily ready).
  • ReleaseFailed - an installation or upgrade failed.
  • Irreconcilable - an error occurred during reconciliation

func (*Reconciler) SetupWithManager

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager configures a controller for the Reconciler and registers watches. It also uses the passed Manager to initialize default values for the Reconciler and sets up the manager's scheme with the Reconciler's configured GroupVersionKind.

If an error occurs setting up the Reconciler with the manager, it is returned.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL