Commit Graph

73 Commits

Author SHA1 Message Date
Aurel Canciu 7c75fc4d3d
Fix HelmRelease reconciliation loop
Likely after the upgrade to controller-runtime v0.15.0 a regression
surfaced for long-running reconciliations of HelmRelease resources (e.g.
for charts having pre-upgrade hooks taking a few minutes to complete).
This regression would cause the controller to immediately re-run the
upgrade after a successful upgrade, thus entering an almost-endless
loop.

Apparently, the only fix to this issue is to ensure
`.Status.LastReleaseRevision` is updated as soon as possible in the
reconiliation cycle rather than wait for the update at the end of the
cycle.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2023-06-20 14:52:50 +03:00
Hidde Beydals 2ea7393629
Include revision and token in event metadata
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-31 13:01:50 +02:00
Hidde Beydals 4df753a1f1
Use last attempted values checksum as event metadata token
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-24 14:23:11 +02:00
Hidde Beydals d345af0e73
Rename controllers to controller
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-24 11:05:53 +02:00
Hidde Beydals 2ba28c6d9e
Update Kubernetes, controller-runtime and Helm
This commit updates Kubernetes to v1.27, controller-runtime to
v0.15, and Helm to v3.12.

It deals with various breaking changes in controller-runtime, as
documented in the release notes:
https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0

In short:

- `Watches` now use a `client.Object` instead of a `source.Kind`.
- `handler.MapFunc` signature accepts a Go context, which is used to
  log any errors, instead of silently ignoring them and/or panicking.
- Max concurrent reconciles is configured on the manager, instead of
  configuring them per reconciler instance.
- Various manager configuration options have been moved to new
  structures and/or fields.

In addition to this, all other dependencies which had updates
available are updated to their latest versions as well.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-24 10:39:51 +02:00
longquan0104 30b131ab1c
Stable sort release values by key
This commit changes the way the checksum is calculated for the release
values, by stable sorting the keys. By doing this, an upgrade will not
be triggered when a key/value pair has just been moved, instead of
containing a real change of value.

To make it backwards compatible (and without triggering an upgrade due
to new ordering), the checksum without ordering is continued to be
calculated and compared against until removal in a future controller
release. However, only the checksum of the ordered values is taken note
of in the Status of the HelmRelease.

Co-authored-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: longquan0104 <longquan0104@gmail.com>
2023-05-11 10:17:52 +02:00
Hidde Beydals 32b5d7ec1b
Fix nil pointer deref during diff attempt
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-04-12 11:41:12 +02:00
Stefan Prodan 18ed296944
Fix chart metadata by making it truly optional
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-04-03 17:22:50 +03:00
Hidde Beydals 2de972cb8f
Update to source-controller v1.0.0-rc.1
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-31 09:37:28 +02:00
Hidde Beydals c93b3afe16
controllers: propagate `PersistentClient` value
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-30 16:14:15 +02:00
Hidde Beydals 6f85ca58d7
kube: make persistent client opt-in configuration
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-30 16:14:15 +02:00
Hidde Beydals ad21e7e3c8
controllers: update status patch logic
Hotfix to deal with the issue, as we will soon be moving to the patch
logic used by already rewritten controllers. This is however a pain for
many users, so worth solving now.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-30 15:42:39 +02:00
Hidde Beydals a72a2fc6ca
misc: tidy HelmChart annotation and labels feat
- Assing `ObjectMeta` field in Helm chart template.
- Ensure things are at least lightly mentioned in spec documentation.
- Add two simple test cases.
- Fix broken links to Kubernetes documentation.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-29 14:32:13 +02:00
Raffael Sahli 2cc2fee410 feat: manage label and annotations for a helmchart
Signed-off-by: Raffael Sahli <raffael.sahli@doodle.com>
2023-03-29 14:18:40 +02:00
Hidde Beydals a12fd2aa93
api: update dependencies
- github.com/fluxcd/pkg/apis/kustomize to v1.0.0
- github.com/fluxcd/pkg/apis/meta to v1.0.0
- k8s.io/apiextensions-apiserver to v0.26.3
- k8s.io/apimachinery to v0.26.3

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-27 18:36:30 +02:00
Hidde Beydals 3615feef2a
Move `controllers` to `internal/controllers`
There is no good reason for it to be exposed and available through a
public API, and this follows the new kubebuilder defaults.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-27 17:25:31 +02:00
Hidde Beydals 0b8b92ba64
Allow opt-out of drift correction
This enhances the drift detection to allow detection without acting on
it by adding a `CorrectDrift` feature gate. When set to `false` (i.e.
`--feature-gates=DetectDrift=true,CorrectDrift=false`), the controller
will only log the difference it detected without acting on it.

This allows for a smoother transition to drift detection, as issues
with a number of existing releases can be solved before the feature
is enabled in full.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-20 13:07:08 +01:00
Hidde Beydals b732420f26
oomwatch: auto detect well known cgroup paths
This commit adds support for recognizing cgroup v1 paths, and allows for
the configuration of alternative absolute path locations using
`--oom-watch-max-memory-path` and `--oom-watch-current-memory-path`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-10 15:08:17 +01:00
Hidde Beydals c4566a5459
oomwatch: small tweaks
- Change memory usage percent threshold to `uint8` to no longer allow
  fractions.
- Validate interval to prevent configurations `<50ms`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-07 10:39:31 +01:00
Hidde Beydals cceb71d56e
oomwatch: add test coverage
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-07 10:39:31 +01:00
Hidde Beydals 62456c94ff
Add OOM watcher to allow graceful shutdown
This commit introduces an OOM watcher, which can be enabled using
`--feature-gates=OOMWatch=true`. The OOM watcher watches the current
memory usage as reported by cgroups via `memory.current` and cancels
the context when it reaches a certain threshold compared to
`memory.max` (default `95`%, configurable using
`--oom-watch-memory-threshold`).

This allows ongoing Helm processes to gracefully exit with a failure
before the controller is forcefully OOM killed, preventing a deadlock
of releases in a pending state.

The OOM watcher polls the `memory.current` file on an interval (default
`500ms`, configurable using `--oom-watch-interval`), as subscribing to
file updates using inotify is not possible for cgroups (v2) except for
`*.events` files. Which does provide signals using `memory.events`, but
these will generally be too late for our use case. As for example `high`
equals `max` in most containers, buying us little time to gracefully
stop our processes.

In addition, because we simply watch current usage compared to max
usage in bytes. This approach should work for cgroups v1 as well, given
this has (most of the time) files for these values available, albeit
at times at different locations. For which this commit does not
introduce a flag yet, but the library takes into account that it could
be configured at some point.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-07 10:39:19 +01:00
Hidde Beydals b68592c4cb
runner: reset RESTMapper after CRD change
As otherwise with a persistent discovery client and/or REST mapper
configuration, newly installed CRDs will not be recognized and cause a
`resource mapping not found for name` error.

In addition, remove the `ServerGroups` and `Invalidate` calls. As this
is later done (again) by Helm when gathering server capabilities.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-06 16:54:48 +01:00
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
Hidde Beydals c277c4b800
runner: simplify DebugLog wrapper
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 10:01:09 +01:00
Hidde Beydals 3b25041385
runner: configure Helm action cfg log levels
This reduces the amount of log lines pushed to `debug` by configuring the kube
client and storage loggers to only log to `trace`.

In addition, the log buffer used in events will now just contain the
most relevant information about a failure as reported by the Helm action
itself, and not the in-depth information from the underlying client
and/or storage.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 09:58:35 +01:00
Hidde Beydals f24cf9dc83
helm: enable DNS with AllowDNSLookups feature gate
This allows install and upgrade actions to use DNS lookups while
rendering Helm templates after it got disabled in Helm due to possible
security risks.

It is enabled (globally) on the controller by configuring
`--feature-gates=AllowDNSLookups=true`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 13:55:13 +01:00
Hidde Beydals 38ea587370
Change to `helm.toolkit.fluxcd.io/driftDetection`
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 13:04:13 +01:00
Hidde Beydals 8389593288
diff: prettify premature diff log
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 10:27:46 +01:00
Hidde Beydals 9153649f23
diff: add premature diff debug log
As there are currently no other utilities to properly see what change
the controller detected, this allows people to have an insight into
the observed changes by configuring the controller with
`--log-level=debug`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 10:25:07 +01:00
Hidde Beydals c93e5e1908
diff: additional test cases
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 09:36:43 +01:00
Hidde Beydals b7d8244496
diff: allow exclusion of specific objects
This allows a specific object from a release manifest to be excluded
from drift detection by labeling or annotating it with:
`helm.toolkit.fluxcd.io/diff: disabled`.

Using a Kustomize post renderer definition in a HelmRelease, this can
be used to ignore any object from an arbitrary chart.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 09:36:43 +01:00
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 362a27173e Patch CRDs with origin labels
This allows the applied CRDs to be traced using the same labels as
currently applied to resources using a Kustomize post-render.

Kustomize is not used here as the apply logic for CRDs is different
from the approach used during releasing, where we inject the labels
in such a way that they are written back to the Helm storage in the
rendered manifest. This to match Helm's logic from which our present
code is already derived (buth with support for policies).

This also moves the full responsibility of dealing with the install
of CRDs to ourselves, as we no longer fall back to Helm's logic when
`Create` is configured as a policy during a Helm install. As this
would not allow us to add the labels.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-01-31 15:09:21 +00:00
stoetti 5ea57b72ee assign the value of 'DisableOpenApiValidation' from the HelmRelease-resource to the helm-command 2022-12-20 14:22:27 +00:00
Mac Chaffee 9bcf125e2c
Disable caching of secrets and configmaps by default.
You can re-enabled caching of secrets by starting the
controller with the argument '--feature-gates=CacheSecretsAndConfigMaps=true'

Signed-off-by: Mac Chaffee <machaffe@renci.org>
2022-12-19 09:53:01 -05: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
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
Tomek Rękawek 5b1b1ce642 Support targeted Patches in the PostRenderer specification.
Signed-off-by: Tomek Rękawek <rekawek@adobe.com>
2022-03-11 14:34:28 +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
Samuel Torres 7d6c0f7c47 Add disableWait property on Helm uninstall
This commit changes the default behavior of the Helm uninstall action
to wait for all resources to be deleted, and introduces a
`.spec.uninstall.disableWait` flag to disable this behavior.

Signed-off-by: Samuel Torres <samuelpirestorres@gmail.com>
2022-02-16 12:09:29 +01: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
Aurel Canciu 2c82071f6c
Update flux pkg components
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2022-01-07 17:53:07 +01: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
Hidde Beydals 5f3d3ec3c3 Enquote annotations in expected test result
Enquoting int variables as annotations is beter, and the result of an
upstream patch.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-06-09 13:30:47 +02:00
Hidde Beydals 44ea1d90ce Update dependencies
Controller-runtime has been updated to `v0.9.0`, K8s dependencies to
`v0.21.1`, and all `fluxcd/pkg` and other dependencies to the versions
that have matching dependencies and/or build constraints.

This includes an update of Helm to `v3.6.0`, and an update of the
Kustomize API to match `v4.1.x`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-06-09 13:30:47 +02:00
Santosh Kewat f48b8ab953 Added support for helm waitForJobs
Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Added support for helm waitForJobs

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Minor fixes

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Changed WaitForJobs to DisableWaitForJobs

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Minor fixes

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Changed WaitForJobs to DisableWaitForJobs

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>

Removed unnecessary update to v2alpha1

Signed-off-by: Santosh Kewat <santoshkewat.bitmesra@gmail.com>
2021-06-01 18:47:54 +05:30