Commit Graph

881 Commits

Author SHA1 Message Date
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 154000e583
Merge pull request #630 from fluxcd/kube-improvements 2023-03-07 10:09:21 +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 90a03d05f6
Merge pull request #627 from fluxcd/update-xx
Update tonistiigi/xx to 1.2.1
2023-03-02 17:48:22 +01:00
Hidde Beydals 043dad959c
Update tonistiigi/xx to 1.2.1
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 17:00:55 +01:00
Hidde Beydals 7d3904f035
Merge pull request #626 from fluxcd/update-deps
Update dependencies
2023-03-02 16:00:59 +01:00
Hidde Beydals f803e222bf
e2e: increase timeout on delete-ns test
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 15:45:28 +01:00
Hidde Beydals 344717a292
Update dependencies
- github.com/fluxcd/pkg/apis/event to v0.4.1
- github.com/fluxcd/pkg/apis/kustomize to v0.8.1
- github.com/fluxcd/pkg/apis/meta to v0.19.1
- github.com/fluxcd/pkg/runtime to v0.30.0
- sigs.k8s.io/controller-runtime to v0.14.5
- github.com/containerd/containerd to v1.6.18

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 14:42:54 +01:00
Hidde Beydals 8becd60cbd
api: update dependencies
- github.com/fluxcd/pkg/apis/kustomize to v0.8.1
- github.com/fluxcd/pkg/apis/meta to v0.19.1
- sigs.k8s.io/controller-runtime to v0.14.5

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-02 14:41:32 +01:00
Hidde Beydals 1f5c565123
Merge pull request #623 from aryan9600/sa-check
check if service account exists before uninstalling release
2023-03-02 14:41:10 +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 8d7b650a22
Merge pull request #625 from fluxcd/helm-log-levels
runner: configure Helm action cfg log levels
2023-03-02 10:22:41 +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 877c4c7d39
Merge pull request #624 from fluxcd/build-go-1.20
build: update to Go 1.20
2023-03-01 16:05:04 +01:00
Hidde Beydals f1a270aefb
build: update to Go 1.20
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 15:52:08 +01:00
Hidde Beydals 78117fccc1
Merge pull request #621 from fluxcd/allow-dns-lookups
helm: enable DNS with AllowDNSLookups feature gate
2023-03-01 15:51:41 +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 9abcdd6a41
Merge pull request #622 from fluxcd/update-deps
Update dependencies
2023-03-01 13:54:24 +01:00
Hidde Beydals 9d3fd3d83b
Update dependencies
- github.com/fluxcd/source-controller/api to v0.35.2
- github.com/onsi/gomega to v1.27.2
- k8s.io/api to v0.26.2
- k8s.io/apiextensions-apiserver to v0.26.2
- k8s.io/apimachinery to v0.26.2
- k8s.io/cli-runtime to v0.26.2
- k8s.io/client-go to v0.26.2
- k8s.io/utils to v0.0.0-20230220204549-a5ecb0141aa5
- Unpin github.com/emicklei/go-restful as it is no longer an (indirect)
  dependency.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 13:38:03 +01:00
Hidde Beydals 87044ba4a0
api: update dependencies
- k8s.io/apiextensions-apiserver v0.26.2
- k8s.io/apimachinery v0.26.2

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 13:30:37 +01:00
Hidde Beydals 788115965a
Merge pull request #617 from fluxcd/detect-drift
Experimental support of drift detection
2023-03-01 13:17:33 +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 ff07f52dee
docs: enrich drift detection docs
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 13:04:12 +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 8c4b2885b2
docs: document experimental drift detection
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 09:36:43 +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 16ce900b20
api: switch to `meta.KubeConfigReference`
This is backwards compatible, as it only changes the type without the
further requirements around the YAML declaration.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-01 09:36:43 +01:00
Hidde Beydals d5dd5a91c8
Merge pull request #620 from fluxcd/helm-action-ctx
helm: propagate context to install and upgrade
2023-02-27 15:13:19 +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 5f465cf7d8
Merge pull request #614 from fluxcd/fix-snyk
ci: Fix Snyk code scanning
2023-02-17 13:10:29 +01:00
Stefan Prodan 4c58aa8da2
ci: Fix Snyk code scanning
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-02-17 12:56:03 +02:00
Hidde Beydals 41f530928c
Merge pull request #613 from fluxcd/release-0.30.0
Release v0.30.0
2023-02-17 10:49:14 +01:00
Hidde Beydals 2e52949426 Release v0.30.0
Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-17 10:34:53 +01:00
Hidde Beydals f8ea4505d7
Merge pull request #612 from fluxcd/update-deps
Update source-controller to v0.35.1
2023-02-17 10:05:13 +01:00
Hidde Beydals 43e7fbef7b Update source-controller to v0.35.1
Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-17 09:41:47 +01:00
Hidde Beydals 67a096d5f4
Merge pull request #610 from fluxcd/update-deps
Update dependencies
2023-02-16 18:47:33 +01:00
Hidde Beydals db7ce7e695 Update controller API build tooling
- Update both to their latest versions
- Introduce version variables

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-16 17:54:51 +01:00
Hidde Beydals db286fe8c7 Update dependencies
- github.com/fluxcd/pkg/apis/event to v0.4.0
- github.com/fluxcd/pkg/runtime to v0.29.0
- helm.sh/helm/v3 to v3.11.1
- k8s.io/utils to v0.0.0-20230209194617-a36077c30491
- github.com/containerd/containerd to v1.6.18

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-16 17:54:51 +01:00
Hidde Beydals 8aedb5de24 api: update dependencies
- sigs.k8s.io/controller-runtime to v0.14.4
- Unpin golang.org/x/text from v0.4.0 to allow update to v0.5.0

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-16 17:49:08 +01:00
Hidde Beydals 2d2c9aaed8
Merge pull request #606 from fluxcd/digest-revision-fmt
Support RFC-0005 revision format
2023-02-16 17:47:02 +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
Hidde Beydals 16fd8f9420
Merge pull request #598 from fluxcd/release-0.29.0
Release v0.29.0
2023-02-01 15:14:35 +00:00
Hidde Beydals fff787d60b Release v0.29.0
Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-01 15:02:45 +00:00
Hidde Beydals b0a9e77ace
Merge pull request #597 from fluxcd/update-deps
Update source-controller to v0.34.0
2023-02-01 14:45:10 +00:00
Hidde Beydals 6a7949951e Update source-controller to v0.34.0
Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-02-01 14:28:11 +00:00