reconcile

package
v0.37.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExceededMaxRetries is returned when there are no remaining retry
	// attempts for the provided release config.
	ErrExceededMaxRetries = errors.New("exceeded maximum retries")

	// ErrMustRequeue is returned when the caller must requeue the object
	// to continue the reconciliation process.
	ErrMustRequeue = errors.New("must requeue")

	// ErrMissingRollbackTarget is returned when the rollback target is missing.
	ErrMissingRollbackTarget = errors.New("missing target release for rollback")

	// ErrUnknownReleaseStatus is returned when the release status is unknown
	// and cannot be acted upon.
	ErrUnknownReleaseStatus = errors.New("unknown release status")

	// ErrUnknownRemediationStrategy is returned when the remediation strategy
	// is unknown.
	ErrUnknownRemediationStrategy = errors.New("unknown remediation strategy")
)
View Source
var (
	// ErrNoLatest is returned when the HelmRelease has no latest release
	// but this is required by the ActionReconciler.
	ErrNoLatest = errors.New("no latest release")
	// ErrReleaseMismatch is returned when the resulting release after running
	// an action does not match the expected latest and/or previous release.
	// This can happen for actions where targeting a release by version is not
	// possible, for example while running tests.
	ErrReleaseMismatch = errors.New("release mismatch")
)
View Source
var (
	ErrNoStorageUpdate = errors.New("release not updated in Helm storage")
)

OwnedConditions is a list of Condition types owned by the HelmRelease object.

Functions

This section is empty.

Types

type ActionReconciler

type ActionReconciler interface {
	// Reconcile performs the reconcile action for the given Request. The
	// reconciler should write the result of the request to the Object's status.
	// An error is returned if the reconcile action cannot be performed and did
	// not result in a modification of the Helm storage. The caller should then
	// either retry, or abort the operation.
	Reconcile(ctx context.Context, req *Request) error
	// Name returns the name of the ActionReconciler. Typically, this equals
	// the name of the Helm action it performs.
	Name() string
	// Type returns the ReconcilerType of the ActionReconciler.
	Type() ReconcilerType
}

ActionReconciler is an interface which defines the methods that a reconciler of a Helm action must implement.

type AtomicRelease

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

AtomicRelease is an ActionReconciler which implements an atomic release strategy similar to Helm's `--atomic`, but with more advanced state determination. It determines the next action to take based on the current state of the Request.Object and other data, and the state of the Helm release.

This process will continue until an action is called multiple times, no action remains, or a remediation action is called. In which case, the process will stop to be resumed at a later time or be checked upon again, by e.g. a requeue.

Before running the ActionReconciler for the next action, the object is marked with Reconciling=True and the status is patched. This condition is removed when the ActionReconciler process is done.

When it determines the object is out of remediation retries, the object is marked with Stalled=True.

The status conditions are summarized into a Ready condition when no actions to be run remain, to ensure any transient error is cleared.

Any returned error other than ErrExceededMaxRetries should be retried by the caller as soon as possible, preferably with a backoff strategy. In case of ErrMustRequeue, it is advised to requeue the object outside the interval to ensure continued progress.

The caller is expected to patch the object one last time with the Request.Object result to persist the final observation. As there is an expectation they will need to patch the object anyway to e.g. update the ObservedGeneration.

For more information on the individual ActionReconcilers, refer to their documentation.

func NewAtomicRelease

func NewAtomicRelease(patchHelper *patch.SerialPatcher, cfg *action.ConfigFactory, recorder record.EventRecorder, fieldManager string) *AtomicRelease

NewAtomicRelease returns a new AtomicRelease reconciler configured with the provided values.

func (*AtomicRelease) Name

func (r *AtomicRelease) Name() string

func (*AtomicRelease) Reconcile

func (r *AtomicRelease) Reconcile(ctx context.Context, req *Request) error

func (*AtomicRelease) Type

func (r *AtomicRelease) Type() ReconcilerType

type CorrectClusterDrift

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

CorrectClusterDrift is a reconciler that attempts to correct the cluster state of a Helm release. It does so by applying the Helm release's desired state to the cluster based on a jsondiff.DiffSet.

The reconciler will only attempt to correct the cluster state if the Helm release has drift detection enabled and the jsondiff.DiffSet is not empty.

The reconciler will emit a Kubernetes event upon completion indicating whether the cluster state was successfully corrected or not.

func NewCorrectClusterDrift

func NewCorrectClusterDrift(configFactory *action.ConfigFactory, recorder record.EventRecorder, diff jsondiff.DiffSet, fieldManager string) *CorrectClusterDrift

func (*CorrectClusterDrift) Name

func (r *CorrectClusterDrift) Name() string

func (*CorrectClusterDrift) Reconcile

func (r *CorrectClusterDrift) Reconcile(ctx context.Context, req *Request) error

func (*CorrectClusterDrift) Type

type HelmChartTemplate

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

HelmChartTemplate attempts to create, update or delete a v1beta2.HelmChart based on the given Request data.

It does this by building a v1beta2.HelmChart from the template declared in the v2beta2.HelmRelease, and then reconciling that v1beta2.HelmChart using a server-side apply.

When the server-side apply succeeds, the namespaced name of the chart is written to the Status.HelmChart field of the v2beta2.HelmRelease. If the server-side apply fails, the error is returned to the caller and indicates they should retry.

When at the beginning of the reconciliation the deletion timestamp is set on the v2beta2.HelmRelease, or the Status.HelmChart differs from the namespaced name of the chart to be applied, the existing chart is deleted. The deletion is observed, and when it completes, the Status.HelmChart is cleared. If the deletion fails, the error is returned to the caller and indicates they should retry.

In case the v2beta2.HelmRelease is marked for deletion, the reconciler will not continue to attempt to create or update the v1beta2.HelmChart.

func NewHelmChartTemplate

func NewHelmChartTemplate(client client.Client, recorder record.EventRecorder, fieldManager string) *HelmChartTemplate

NewHelmChartTemplate returns a new HelmChartTemplate reconciler configured with the provided values.

func (*HelmChartTemplate) Reconcile

func (r *HelmChartTemplate) Reconcile(ctx context.Context, req *Request) error

type Install

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

Install is an ActionReconciler which attempts to install a Helm release based on the given Request data.

Before the installation, the History in the Status of the Request.Object is cleared to mark the start of a new release lifecycle. This ensures we never attempt to roll back to a previous release before the install.

During the installation process, the writes to the Helm storage are observed and recorded in the Status.History field of the Request.Object.

On installation success, the object is marked with Released=True and emits an event. In addition, the object is marked with TestSuccess=False if tests are enabled to indicate we are awaiting the results. On failure, the object is marked with Released=False and emits a warning event. Only an error which resulted in a modification to the Helm storage counts towards a failure for the active remediation strategy.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewInstall

func NewInstall(cfg *action.ConfigFactory, recorder record.EventRecorder) *Install

NewInstall returns a new Install reconciler configured with the provided values.

func (*Install) Name

func (r *Install) Name() string

func (*Install) Reconcile

func (r *Install) Reconcile(ctx context.Context, req *Request) error

func (*Install) Type

func (r *Install) Type() ReconcilerType

type ReconcilerType

type ReconcilerType string

ReconcilerType is a string which identifies the type of ActionReconciler. It can be used to e.g. limiting the number of action (types) to be performed in a single reconciliation.

const (
	// ReconcilerTypeRelease is an ActionReconciler which produces a new
	// Helm release.
	ReconcilerTypeRelease ReconcilerType = "release"
	// ReconcilerTypeRemediate is an ActionReconciler which remediates a
	// failed Helm release.
	ReconcilerTypeRemediate ReconcilerType = "remediate"
	// ReconcilerTypeTest is an ActionReconciler which tests a Helm release.
	ReconcilerTypeTest ReconcilerType = "test"
	// ReconcilerTypeUnlock is an ActionReconciler which unlocks a Helm
	// release in a stale pending state. It differs from ReconcilerTypeRemediate
	// in that it does not produce a new Helm release.
	ReconcilerTypeUnlock ReconcilerType = "unlock"
	// ReconcilerTypeDriftCorrection is an ActionReconciler which corrects
	// Helm releases which have drifted from the cluster state.
	ReconcilerTypeDriftCorrection ReconcilerType = "drift correction"
)

type ReconcilerTypeSet

type ReconcilerTypeSet []ReconcilerType

ReconcilerTypeSet is a set of ReconcilerType.

func (ReconcilerTypeSet) Contains

func (s ReconcilerTypeSet) Contains(t ReconcilerType) bool

Contains returns true if the set contains the given type.

func (ReconcilerTypeSet) Count

Count returns the number of elements matching the given type.

type ReleaseState

type ReleaseState struct {
	// Status is the status of the release.
	Status ReleaseStatus
	// Reason for the Status.
	Reason string
	// Diff contains any differences between the Helm storage manifest and the
	// cluster state when Status equals ReleaseStatusDrifted.
	Diff jsondiff.DiffSet
}

ReleaseState represents the state of a Helm release as determined by comparing the Helm storage with the v2beta2.HelmRelease object.

func DetermineReleaseState

func DetermineReleaseState(ctx context.Context, cfg *action.ConfigFactory, req *Request) (ReleaseState, error)

DetermineReleaseState determines the state of the Helm release as compared to the v2beta2.HelmRelease object. It returns a ReleaseState that indicates the status of the release, and an error if the state could not be determined.

type ReleaseStatus

type ReleaseStatus string

ReleaseStatus represents the status of a Helm release as determined by comparing the Helm storage with the v2beta2.HelmRelease object.

const (
	// ReleaseStatusUnknown indicates that the status of the release could not
	// be determined.
	ReleaseStatusUnknown ReleaseStatus = "Unknown"
	// ReleaseStatusAbsent indicates that the release is not present in the
	// Helm storage.
	ReleaseStatusAbsent ReleaseStatus = "Absent"
	// ReleaseStatusUnmanaged indicates that the release is present in the Helm
	// storage, but is not managed by the v2beta2.HelmRelease object.
	ReleaseStatusUnmanaged ReleaseStatus = "Unmanaged"
	// ReleaseStatusOutOfSync indicates that the release is present in the Helm
	// storage, but is not in sync with the v2beta2.HelmRelease object.
	ReleaseStatusOutOfSync ReleaseStatus = "OutOfSync"
	// ReleaseStatusDrifted indicates that the release is present in the Helm
	// storage, but the cluster state has drifted from the manifest in the
	// storage.
	ReleaseStatusDrifted ReleaseStatus = "Drifted"
	// ReleaseStatusLocked indicates that the release is present in the Helm
	// storage, but is locked.
	ReleaseStatusLocked ReleaseStatus = "Locked"
	// ReleaseStatusUntested indicates that the release is present in the Helm
	// storage, but has not been tested.
	ReleaseStatusUntested ReleaseStatus = "Untested"
	// ReleaseStatusInSync indicates that the release is present in the Helm
	// storage, and is in sync with the v2beta2.HelmRelease object.
	ReleaseStatusInSync ReleaseStatus = "InSync"
	// ReleaseStatusFailed indicates that the release is present in the Helm
	// storage, but has failed.
	ReleaseStatusFailed ReleaseStatus = "Failed"
)

func (ReleaseStatus) String

func (s ReleaseStatus) String() string

String returns the string representation of the release status.

type Request

type Request struct {
	// Object is the Helm release to be reconciled, and describes the desired
	// state to the ActionReconciler.
	Object *v2.HelmRelease
	// Chart is the Helm chart to be installed or upgraded.
	Chart *helmchart.Chart
	// Values is the Helm chart values to be used for the installation or
	// upgrade.
	Values helmchartutil.Values
}

Request is a request to be performed by an ActionReconciler. The reconciler writes the result of the request to the Object's status.

type RollbackRemediation

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

RollbackRemediation is an ActionReconciler which attempts to roll back a Request.Object to a previous successful deployed release in the Status.History.

The writes to the Helm storage during the rollback are observed, and update the Status.History field.

After a successful rollback, the object is marked with Remediated=True and an event is emitted. When the rollback fails, the object is marked with Remediated=False and a warning event is emitted.

When the Request.Object does not have a (successful) previous deployed release, it returns an error of type ErrMissingRollbackTarget. In addition, it returns ErrReleaseMismatch if the name and/or namespace of the latest and previous release do not match. Any other returned error indicates the caller should retry as it did not cause a change to the Helm storage.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewRollbackRemediation

func NewRollbackRemediation(configFactory *action.ConfigFactory, eventRecorder record.EventRecorder) *RollbackRemediation

NewRollbackRemediation returns a new RollbackRemediation reconciler configured with the provided values.

func (*RollbackRemediation) Name

func (r *RollbackRemediation) Name() string

func (*RollbackRemediation) Reconcile

func (r *RollbackRemediation) Reconcile(ctx context.Context, req *Request) error

func (*RollbackRemediation) Type

type Test

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

Test is an ActionReconciler which attempts to perform a Helm test for the latest release of the Request.Object.

The writes to the Helm storage during testing are observed, which causes the TestHooks field of the latest Snapshot in the Status.History to be updated if it matches the target of the test.

When all test hooks for the release succeed, the object is marked with TestSuccess=True and an event is emitted. When one of the test hooks fails, Helm stops running the remaining tests, and the object is marked with TestSuccess=False and a warning event is emitted. If test failures are not ignored, the failure count for the active remediation strategy is incremented.

When the Request.Object does not have a latest release, it returns an error of type ErrNoLatest. In addition, it returns ErrReleaseMismatch if the test ran for a different release target than the latest release. Any other returned error indicates the caller should retry as it did not cause a change to the Helm storage.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewTest

func NewTest(cfg *action.ConfigFactory, recorder record.EventRecorder) *Test

NewTest returns a new Test reconciler configured with the provided values.

func (*Test) Name

func (r *Test) Name() string

func (*Test) Reconcile

func (r *Test) Reconcile(ctx context.Context, req *Request) error

func (*Test) Type

func (r *Test) Type() ReconcilerType

type Uninstall

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

Uninstall is an ActionReconciler which attempts to uninstall a Helm release based on the given Request data.

The writes to the Helm storage during the uninstallation are observed, and update the Status.History field.

After a successful uninstall, the object is marked with Released=False and an event is emitted. When the uninstallation fails, the object is marked with Released=False and a warning event is emitted.

When the Request.Object does not have a latest release, it returns an error of type ErrNoLatest. If the uninstallation targeted a different release (version) than the latest release, it returns an error of type ErrReleaseMismatch. In addition, it returns ErrNoStorageUpdate if the uninstallation completed without updating the Helm storage. In which case the resources for the release will be removed from the cluster, but the storage object remains in the cluster. Any other returned error indicates the caller should retry as it did not cause a change to the Helm storage or the cluster resources.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

This reconciler is different from UninstallRemediation, in that it makes observations to the Released condition type instead of Remediated. Use this reconciler to uninstall a release, and UninstallRemediation to remediate a release.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewUninstall

func NewUninstall(cfg *action.ConfigFactory, recorder record.EventRecorder) *Uninstall

NewUninstall returns a new Uninstall reconciler configured with the provided values.

func (*Uninstall) Name

func (r *Uninstall) Name() string

func (*Uninstall) Reconcile

func (r *Uninstall) Reconcile(ctx context.Context, req *Request) error

func (*Uninstall) Type

func (r *Uninstall) Type() ReconcilerType

type UninstallRemediation

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

UninstallRemediation is an ActionReconciler which attempts to remediate a failed Helm release for the given Request data by uninstalling it.

The writes to the Helm storage during the rollback are observed, and update the Status.History field.

After a successful uninstall, the object is marked with Remediated=True and an event is emitted. When the uninstallation fails, the object is marked with Remediated=False and a warning event is emitted.

When the Request.Object does not have a latest release, it returns an error of type ErrNoLatest. If the uninstallation targeted a different release (version) than the latest release, it returns an error of type ErrReleaseMismatch. In addition, it returns ErrNoStorageUpdate if the uninstallation completed without updating the Helm storage. In which case the resources for the release will be removed from the cluster, but the storage object remains in the cluster. Any other returned error indicates the caller should retry as it did not cause a change to the Helm storage or the cluster resources.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

This reconciler is different from Uninstall, in that it makes observations to the Remediated condition type instead of Released. Use this reconciler to remediate a failed release, and Uninstall to uninstall a release.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewUninstallRemediation

func NewUninstallRemediation(cfg *action.ConfigFactory, recorder record.EventRecorder) *UninstallRemediation

NewUninstallRemediation returns a new UninstallRemediation reconciler configured with the provided values.

func (*UninstallRemediation) Name

func (r *UninstallRemediation) Name() string

func (*UninstallRemediation) Reconcile

func (r *UninstallRemediation) Reconcile(ctx context.Context, req *Request) error

func (*UninstallRemediation) Type

type Unlock

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

Unlock is an ActionReconciler which attempts to unlock the latest release for a Request.Object in the Helm storage if stuck in a pending state, by setting the status to release.StatusFailed and persisting it.

This write to the Helm storage is observed, and updates the Status.History field if the persisted object targets the same release version.

Any pending state marks the v2beta2.HelmRelease object with ReleasedCondition=False, even if persisting the object to the Helm storage fails.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

func NewUnlock

func NewUnlock(cfg *action.ConfigFactory, recorder record.EventRecorder) *Unlock

NewUnlock returns a new Unlock reconciler configured with the provided values.

func (*Unlock) Name

func (r *Unlock) Name() string

func (*Unlock) Reconcile

func (r *Unlock) Reconcile(_ context.Context, req *Request) error

func (*Unlock) Type

func (r *Unlock) Type() ReconcilerType

type Upgrade

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

Upgrade is an ActionReconciler which attempts to upgrade a Helm release based on the given Request data.

The writes to the Helm storage during the upgrade process are observed, and update the Status.History field.

On upgrade success, the object is marked with Released=True and emits an event. In addition, the object is marked with TestSuccess=False if tests are enabled to indicate we are awaiting the results. On failure, the object is marked with Released=False and emits a warning event. Only an error which resulted in a modification to the Helm storage counts towards a failure for the active remediation strategy.

At the end of the reconciliation, the Status.Conditions are summarized and propagated to the Ready condition on the Request.Object.

The caller is assumed to have verified the integrity of Request.Object using e.g. action.VerifySnapshot before calling Reconcile.

func NewUpgrade

func NewUpgrade(cfg *action.ConfigFactory, recorder record.EventRecorder) *Upgrade

NewUpgrade returns a new Upgrade reconciler configured with the provided values.

func (*Upgrade) Name

func (r *Upgrade) Name() string

func (*Upgrade) Reconcile

func (r *Upgrade) Reconcile(ctx context.Context, req *Request) error

func (*Upgrade) Type

func (r *Upgrade) Type() ReconcilerType

Jump to

Keyboard shortcuts

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