Commit Graph

125 Commits

Author SHA1 Message Date
Hidde Beydals 34d87ccc24
kube: unify clients into single RESTClientGetter
This drops the twofold implementation in favor of a single
`MemoryRESTClientGetter` which can work with an arbitrary `rest.Config`.

The new `MemoryRESTClientGetter` lazy-loads and caches the objects it
initializes, thereby creating at most one instance of each object for
the duration of the reconcile of a single `HelmRelease` object.

Based on some initial tests, this seems to reduce the overal memory
footprint of the controller.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-06 11:21:18 +01:00
Sanskar Jaiswal 5dbdbd1299 check if service account exists before uninstalling release
Check if the service account to be impersonated actually exists
and proceed with uninstalling the Helm release only if it does.
Otherwise, skip uninstalling the release and carry on with finalization.
Add an e2e test to check if deleting a namespace with the RBAC and
HelmRelease succeeds with the namespace being fully deleted.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-03-02 18:13:26 +05:30
Hidde Beydals 1240f20183
Enable experimental drift detection
This enables experimental drift detection of cluster state compared to
the current manifest data from the Helm storage's manifest blob.

Drift detection works based on the already proven approach of the
kustomize-controller's SSA package, and utilizes the managed field
configured by the controller since `v0.12.2`.

This feature is planned to go out of experimental once the further
controller rewrite has been finished, and the state of the Helm storage
itself is more fault tolerant.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 09:36:43 +01:00
Hidde Beydals 8a9ba1c12c
helm: propagate context to install and upgrade
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-02-27 10:32:44 +01:00
Hidde Beydals 8b3edfd7b9 Support RFC-0005 revision format
This updates all the comparisons to make use of `HasRevision` which
supports the RFC-0005 and legacy revision formats.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-16 17:10:08 +01:00
Stefan Prodan 7b19e37eb8
Update dependencies
- helm.sh/helm/v3 v3.11.0
- k8s.io/* v0.26.1
- sigs.k8s.io/controller-runtime v0.14.2
- github.com/fluxcd/pkg/runtime v0.27.0

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-01-31 16:51:15 +02:00
Stefan Prodan f5d314c51a
Use Flux Event API v1beta1
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-11-08 16:26:31 +02:00
Santosh Kaluskar d196698980 Enable RecoverPanic option on reconciler
Signed-off-by: Santosh Kaluskar <dtshbl@gmail.com>
2022-08-12 17:59:16 +05:30
Hidde Beydals 713f057ad8 tidy: remove obsolete append
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-06-07 14:23:54 +02:00
Hidde Beydals d19b470412 kube: configure proper account impersonation NS
Fixing a regression introduced in #480 which would always pick the
namespace of the release. In addition, historically seen the
configuration of the impersonation username while making use of a
KubeConfig has never worked correctly, this has been adressed as well.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-06-07 12:52:36 +02:00
Hidde Beydals 1bed542fe4 internal/kube: get REST config from runtime
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-12 12:55:36 +02:00
Hidde Beydals 5784f0644a kube: explicitly set ConfigFlags.CacheDir to nil
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-12 12:18:41 +02:00
Hidde Beydals 4371610e4b Cherry-pick kube changes from dev
This is a partial cherry-pick of commit ae4f499e87, including
changes around `kube`. This to include some of the changes around the
construction of the ConfigFlags RESTClientGetter, as an attempt to
solve token refresh issues.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-12 12:18:41 +02:00
Hidde Beydals 2c36cb5eda kubeconfig: err on missing declared SecretRef.Key
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-29 21:46:11 +02:00
Nick Stogner 9f60433550 Add .spec.kubeConfig.secretRef.key
Signed-off-by: Nick Stogner <nicholas.stogner@gmail.com>
2022-04-28 13:19:22 +02:00
Alex Marston 42aaf61852 Add flags for exponential back-off retry
Signed-off-by: Alex Marston <alexander.marston@gmail.com>
2022-04-19 14:25:51 +02:00
Paulo Gomes 6f4ca28c9a
Add flags to control kubeconfig support
Two new flags were added to allow users to enable the
use of user.Exec and InsecureTLS in the kubeconfigs
provided remote apply reconciliations.

Breaking change: both functionalities are no longer
enabled by default.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-31 14:51:38 +01:00
Hidde Beydals 87ffcbcbf9 Prefix revision annotation with API Group FQDN
This to facilitate improvements on the notification-controller side,
where annotations prefixed with the FQDN of the Group of the Involved
Object will be transformed into "fields".

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-23 19:20:41 +01:00
Sunny 6bd29a729d Use new standardized runtime and meta package
This includes an update of the source-controller to v0.22.0, to pull in
the v1beta2 API which makes use of the same packages.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-03-18 13:10:32 +01:00
Stefan Prodan 1410615554
Set QPS and Burst when impersonating service account
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-02-21 14:25:27 +02:00
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