Commit Graph

94 Commits

Author SHA1 Message Date
Hidde Beydals 39e6475822 Revert "Record suspend metrics"
https://github.com/fluxcd/helm-controller/pull/234#issuecomment-801000679

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-03-17 13:24:29 +01:00
Somtochi Onyekwere 8b2ba595bf Record suspend metrics
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2021-03-16 23:45:50 +01:00
Max Jonas Werner 199636f27a
fix: log messages contain '%s'
Before:

{"level":"info","ts":"2021-03-03T12:45:41.305Z","logger":"controller.helmrelease","msg":"could not find optional %s '%s'","reconciler group":"helm.toolkit.fluxcd.io","reconciler kind":"HelmRelease","name":"cert-manager","namespace":"kommander","ConfigMap":{"namespace":"kommander","name":"cert-manager-overrides"}}

After:

{"level":"info","ts":"2021-03-03T13:56:46.365+0100","logger":"controller.helmrelease","msg":"could not find optional ConfigMap 'kommander/cert-manager-overrides'","reconciler group":"helm.toolkit.fluxcd.io","reconciler kind":"HelmRelease","name":"cert-manager","namespace":"kommander"}

Signed-off-by: Max Jonas Werner <mwerner@d2iq.com>
2021-03-03 13:57:51 +01:00
Stefan Prodan a8dcafaf2e
Retry with exponential backoff when fetching artifacts
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-02-26 13:37:45 +02:00
Dylan Arbour 368ca98306 Update pkg/runtime to v0.8.2
pkg/runtime v0.8.2 introduces runtime/transform which includes
`MergeMaps`:
https://github.com/fluxcd/pkg/pull/85

Signed-off-by: Dylan Arbour <arbourd@users.noreply.github.com>
2021-02-15 18:10:19 -05:00
Will Salt 7156abcadf Send specific events for install or upgrade
Signed-off-by: Will Salt <williamejsalt@gmail.com>
2021-02-15 17:20:54 +00:00
Will Salt fcd845c952 add a release deployment event when reconciling a release
Signed-off-by: Will Salt <williamejsalt@gmail.com>
2021-02-15 16:36:19 +00:00
gtracer a5ab88962a add optional storageNamespace
Signed-off-by: gtracer <ganesha.ashoka@gmail.com>

update comments

Signed-off-by: gtracer <ganesha.ashoka@gmail.com>

make test

Signed-off-by: gtracer <ganesha.ashoka@gmail.com>

revert controller-gen version

Signed-off-by: gtracer <ganesha.ashoka@gmail.com>
2021-01-25 17:09:37 +01:00
Hidde Beydals 32693b8106 Upgrade runtime package to v0.6.2
To include a bug fix to the `ReconcilateAtChangedPredicate`
and renaming to `ReconcileRequestedPredicate`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-14 12:32:34 +01:00
Hidde Beydals e511cb8af4 Upgrade controller-runtime to v0.7.0
This commit upgrades the `controller-runtime` dependency to `v0.7.0`,
including all changes required to make all wiring work again.

- Upgrade `runtime` to v0.6.0 to include `controller-runtime` changes.
- Loggers have been removed from the reconcilers and are now retrieved
  from the `context.Context` passed to the `Reconcile` method and
  downwards functions.
- Logger configuration flags are now bound to the flag set using
  `BindFlags` from `runtime/logger`, ensuring the same contract across
  GitOps Toolkit controllers, and the `--log-json` flag has been
  deprecated in favour of the `--log-encoding=json` default.
- The `ChangePredicate` from `runtime` has changed to a
  `ReconcilateAtChangedPredicate`, and is now chained with the
  `GenerationChangedPredicate` from `controller-runtime` using
  `predicate.Or`.
- Signatures that made use of `runtime.Object` have changed to
  `client.Object`, removing the requirement to e.g. call
  `runtime.Object#Object`.
- The `leader-election-role` was changed, as leader election now works
  via the `coordination/v1` API.

Other notable changes:

- `util.ObjectKey` was added to easily construct a `client.ObjectKey` /
  `types.NamespacedName` from a `metav1.Object`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-11 17:41:49 +01:00
Hidde Beydals 8f337e743c Ignore missing release on HR delete
This prevents the resource hanging forever if the release does not exist
in the Helm storage because it was either never created, or because it
was already removed by e.g. Kubernetes due to a namespace deletion.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-30 12:04:17 +01:00
Hidde Beydals 19d1316e31 Always remove finalizer on reconcileDelete
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-26 11:09:17 +01:00
Hidde Beydals 5f2f9aaf74 Do not mark suspended resource as not ready
If a resource is marked as suspended we should not perform any
reconciliation action for the resource at all.

This includes updating the status of the resource to a
`Ready==False` state, as this is not an accurate representation of
the resource's state: we have been told to no longer look at it
and with that our last observation freezes in time.

Resource deletions are the sole exception to actions (not) being
performed, as we are duty-bound to remove our finalizer from the
resource to make a deletion succeed.

To make the suspend state still visible to the user, a column has
been added to the Custom Resource Definition which prints the
`.spec.suspend` of every HelmRelease.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-25 19:21:48 +01:00
Hidde Beydals ecbdf700f5 Use controller-runtime utils for resource deletion
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-25 17:23:36 +01:00
Hidde Beydals 599f3e814e Use DeletionTimestamp for readiness
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-25 15:33:10 +01:00
Hidde Beydals 03d8bea1da Factor out HelmChart reconciliation bits
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-25 15:14:56 +01:00
Stefan Prodan b59f06e9a7
Implement service account impersonation
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-11-24 16:49:13 +02:00
Stefan Prodan b864db2bb8
Requeue after interval on source not found errors
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-11-24 13:13:35 +02:00
Hidde Beydals c0156f193c Refactor to adopt k8s standardized Condition type
Changes the condition type to the one introduced in k8s 1.19, including
the newly introduced helpers in place of the old pkg/apis/meta types.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-19 19:00:55 +01:00
Hidde Beydals f18ddbfce8 Detect chart values file divergences
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-18 10:06:45 +01:00
Hidde Beydals b801b23911 Properly detect chart version divergences
This is a regression bug fix due to the introduction of the default
values in the source-controller CRDs.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-18 10:06:40 +01:00
Hidde Beydals bb85850448 Patch status sub-resource
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-17 11:42:42 +01:00
Hidde Beydals 485b6f5fc8 Requeue on chart load and values composition err
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-17 11:38:55 +01:00
Hidde Beydals fa598261e7 Compare artifact <> HelmRelease in enqueuer
The reason for this is the `EnqueueRequestsFromMapFunc` calling the
enqueuer for _both_ the old and the new object, and we only want to act
on the ones that contain a revision different from the one that we have
recorded in the status object of the `HelmRelease`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-28 22:42:29 +01:00
Hidde Beydals a35a8a9707 Do not requeue when chart is not ready
As the watcher should trigger a reconciliation once the artifact
is available.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-28 14:26:04 +01:00
Hidde Beydals b3baf39e11 Move dedicated watcher to in-controller watcher
This prevents the resources from getting annotated, and instead uses
the `handler.EnqueueRequestsFromMapFunc` to queue requests based on
changes to the source objects.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-28 13:28:11 +01:00
Hidde Beydals 7ac2a41e1a Change copyright to Flux authors
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-27 17:55:18 +01:00
Michael Bridgen 0928cc1e4d Use reconcile annotation helpers
Per https://github.com/fluxcd/pkg/issues/39
2020-10-22 12:26:48 +01:00
Hidde Beydals 15914beca1 Support cross-cluster Helm releases
This is an initial implementation for cross-cluster Helm release
support that relies on a KubeConfig secret, and a reference to it in
the HelmRelease resource.

If set, all actions taken by the Helm runner are executed using the
KubeConfig from the secret. The Helm storage is stored on the remote
cluster in a namespace that equals to the namespace of the HelmRelease
in the managing cluster, the release itself is made in either this
namespace, or the configured TargetNamespace. In any case, both are
expected to exist and/or created beforehand.

Other references to Kubernetes resources in the HelmRelease, like
ValuesReference resources, are expected to exist on the managing
cluster.
2020-10-20 21:30:56 +02:00
Hidde Beydals 236e78d3a1 Change chart reconciliation and readiness logic
By confirming the observed generation is up-to-date before checking
the `Ready` condition state after chart reconciliation, we guarantee
the chart we use for the release always is on par with the state of
the `HelmRelease`.

In addition, we requeue to prevent the `HelmRelease` getting stuck
in a "HelmChart is not ready" state. Previously triggered by a no-op
chart update without a revision change that caused the watcher to
not request a reconciliation for the `HelmRelease`.
2020-10-16 14:39:32 +02:00
Hidde Beydals 3fccbb943f Declare and assign result Values before composing
As `ParseInto` expects the destination to be initialized, which led
to an `unable to parse key: assignment to entry in nil map` error in
configurations where the first `ValuesReference` had a `targetPath`
defined.
2020-10-15 19:12:19 +02:00
Stefan Prodan 1819f143a9
Implement Prometheus instrumentation
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-13 16:24:56 +03:00
Stefan Prodan 6a04f769b2
Update fluxcd/pkg/runtime to v0.1.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-13 15:33:46 +03:00
Hidde Beydals 2fb64a1095 Prevent possible future nil pointer dereference
As the existing logic relied on other conditions that caused the
`released` to never be nil, but this may not be true for future
iterations, which makes this a case of better safe than sorry.
2020-10-05 14:03:44 +02:00
Hidde Beydals 899e8bedc7 Configure release namespace in runner constructor 2020-10-02 19:05:45 +02:00
Hidde Beydals accd4762fe Promote API to v2beta1 2020-09-30 19:37:23 +02:00
Hidde Beydals 8129c49b9c Implement `fluxcd/pkg/apis/meta` in APIs 2020-09-30 12:14:51 +02:00
Hidde Beydals d554a92f81 Record last handled reconcile at annotation
This makes it possible for e.g. the GOTK CLI to observe if the
controller has handled the resource since the manual reconciliation
request was made. It replaces the `LastObservedTime` status field,
as this was prone to time skew issues and does not offer much additional
value over the timestamps of the conditions.
2020-09-29 10:58:04 +02:00
Sean Eagan 30a8f936e2 Fix logging for next run delay
We were logging the spec interval duration, which was incorrect:

1. On failures, which use exponential backoff
2. On dependency not ready, which uses a separately defined static interval.

This changes to log result.RequeueAfter directly when set.
2020-09-28 09:36:29 -05:00
Hidde Beydals d80de0af02 Use single version of values reference on merge
This ensures that a subsequent update to a values reference during
the merging process does not result in an unexpected mixture of old(er)
and new values.
2020-09-28 14:06:56 +02:00
Hidde Beydals 68a8f62a41 Use `ObserveLastRelease` in garbage collector
Which uses `Last()` instead of `Deployed()` to ensure we garbage
collect Helm releases with statuses other than `deployed`,
e.g. `failed`.
2020-09-25 16:18:15 +02:00
Hidde Beydals 4a9a04aa4f Factor out and restructure various elements
* Move `ReleaseRevision` function to util
* Rename `release` method to `reconileRelease` to match
  `reconcileChart`
* Refactor chart artifact download to make use of a temporary file,
  which is removed as soon as the tarbal has been loaded into memory
2020-09-25 16:03:44 +02:00
Hidde Beydals 46d8776b18 Remove reconciliation lock
As the observed generation is now pushed before syncing the resource
(https://github.com/fluxcd/helm-operator/issues/437), and the
controller runtime queue guarantuees there are no consistency
issues (see: https://openkruise.io/en-us/blog/blog2.html).
2020-09-25 15:40:45 +02:00
Hidde Beydals 69ced56bb7 Split HelmChart and HelmRelease garbage collection 2020-09-25 15:40:45 +02:00
Hidde Beydals 7cf267c15c Factor out util functions 2020-09-25 15:40:45 +02:00
Hidde Beydals c526837d76 Factor out Helm actions into runner package 2020-09-25 15:40:41 +02:00
Hidde Beydals 1a88b40936 Support optional values references
This commit adds support for optional values references, as discussions
have brought to light that there are some valid use cases in which
having this option is desirable. For example to allow a user to extend
behaviour at a later date with their own repository without modifying
the HelmRelease object.

When a values reference is marked as optional, not found errors for the
value reference are ignored, but any ValuesKey, TargetPath or transient
error will still result in a reconciliation failure.
2020-09-23 10:00:52 +02:00
Hidde Beydals 8fb854a7b5 Support dependency references to other namespaces
This also removes the sorting from the `HelmChartWatcher`, as with
the current `HelmChartTemplateSpec` a chart is only used by a single
`HelmRelease`. Rendering the action obsolete.
2020-09-15 14:55:11 +02:00
Sean Eagan 0fd937eaee Refactor status API
This removes:

- Installed, Upgraded, RolledBack, and Uninstalled status conditions
  since they did not represent current state, but rather actions
  taken, which are already recorded by events.
- status.observedStateReconciled since it solved the problem of
  remembering past release (install/upgrade/test) success, but not
  past release failures, after other subsequent failures such as
  dependency failures, k8s API failures, etc.

This adds:

- Remediated status condition which records whether the release is
  currently in a remediated state. It is used to prevent release retries
  after remediation failures. We were previously not doing this for
  rollback failures.
- Released status condition which records whether the current state
  has been successfully released (install/upgrade/test). This is used to
  remember the last release attempt status, regardless of any subsequent
  other failures such as dependency failures, k8s API failures, etc.

This renames:

- Tested > TestsSuccess status condition, for forward compatibility
  with interval based helm tests.
2020-09-14 08:12:23 -05:00
Hidde Beydals 2f9d29f693 Support HelmChart ValuesFile field 2020-09-11 14:23:42 +02:00