Commit Graph

105 Commits

Author SHA1 Message Date
Stefan Prodan 0173eaa0df
Allow setting a default service account for impersonation
Introduce the flag `--default-service-account` for allowing cluster admins to enforce impersonation for resources reconciliation.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-01-31 12:09:39 +02:00
Somtochi Onyekwere acf164c46e Add flag to disable cross namespace references
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2022-01-29 13:51:06 +01:00
Kingdon Barrett 0498e9e236 Use patch instead of update when adding finalizers
Signed-off-by: Kingdon Barrett <kingdon@weave.works>
2022-01-13 19:39:36 -05:00
Aurel Canciu 2c82071f6c
Update flux pkg components
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2022-01-07 17:53:07 +01:00
Paulo Gomes 0837f6f34a
Short-circuit event handling
When ExternalEventRecorder is nil, the helm release reference is not used
therefore the function can safely return early.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2021-12-21 14:08:38 +00:00
Paulo Gomes c9b1a4f4f8
Check EventRecorder is not nil
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2021-12-21 14:03:32 +00:00
Stefan Prodan e9d31e9f1f
Make the kubeconfig secrets compatible with SOPS
Add `values.yaml` to the supported kubeconfig secret key names in order for SOPS to correctly detect the storage format based on the file extension.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-04 16:22:09 +03:00
Sunny 91eb550b19
Remove old util ObjectKey
Replace old utility function ObjectKey with controller-runtime's
client.ObjectKeyFromObject.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2021-08-01 03:40:10 +05:30
Zhongcheng Lao c0f72e1fc6
Treat quoted values as string when targetPath is set
Signed-off-by: Zhongcheng Lao <Zhongcheng.Lao@microsoft.com>
2021-07-17 16:42:32 +08:00
Hidde Beydals 314472efb7 Capture (debug) logs from Helm actions
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-03-25 16:08:52 +01:00
Somtochi Onyekwere a9e6820999 Record suspension metrics
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2021-03-17 14:30:09 +01:00
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