Commit Graph

1256 Commits

Author SHA1 Message Date
Hidde Beydals 48cad68386
controller: unready dep should not bump obs gen
This ensures that any unfulfilled dependencies for which we requeue do
not prematurely bump the observed generation by introducing typed
errors.

These typed errors ensure that the logic to bump the observed generation
can continue to be the same, while ignoring them just in time before
returning the final error.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-12-01 14:14:40 +01:00
Hidde Beydals bc7fb25d27
api: limit maximum number of snapshots in history
This ensures that on repetitive failures, the number of snapshots does
not grow indefinitely due to there not being any in a superseded or
deployed state.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-12-01 11:38:56 +01:00
Hidde Beydals 7f9160c66c
Merge pull request #823 from fluxcd/reset-force-annotations
Introduce `forceAt` and `resetAt` annotations
2023-12-01 11:38:43 +01:00
Hidde Beydals 6b7789aadc
Implement `forceAt` and `resetAt` annotations
This makes the controller actually take the
`reconcile.fluxcd.io/forceAt` and `reconcile.fluxcd.io/resetAt` into
account.

For `reconcile.fluxcd.io/resetAt`, this means that the failure counts on
the `HelmRelease` object are reset when the token value of the
annotation equals `reconcile.fluxcd.io/requestedAt`. Allowing the
controller to start over with attempting to install or upgrade the
release until the retries count has been reached again.

For `reconcile.fluxcd.io/forceAt`, this means that a one-off Helm
install or upgrade is allowed to take place even if the object is out of
retries, in a failed state where it should be remediated, or in-sync.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-30 10:22:49 +01:00
Hidde Beydals 7a15000b4c
api: introduce `forceAt` and `resetAt` annotations
This introduces two new annotations:

- `reconcile.fluxcd.io/resetAt`: to reset the failure counts for a
  `HelmRelease` object.
- `reconcile.fluxcd.io/forceAt`: to allow a one-off Helm install or
  upgrade when the controller would otherwise do nothing (e.g. due to
  being out of retries, in-sync, in a failed state, etc.)

Both annotations require the `reconcile.fluxcd.io/requestedAt`
annotation to be set at the same time, with the same token value.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-30 10:22:48 +01:00
Hidde Beydals d310c8b2de
Merge pull request #822 from fluxcd/correct-drift-apply
Correct cluster drift using patches
2023-11-30 10:21:39 +01:00
Hidde Beydals 0131f2227b
action/diff: include Helm metadata in objects
This ensures that the metadata labels and annotations Helm adds during
the creation of resources are included while diffing them.

As they are not part of the manifest but should be restored in case
they are e.g. removed or modified.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-30 09:41:05 +01:00
Hidde Beydals ccd8f88282
Correct cluster drift using patches
This changes the cluster drift correction behavior from performing a
Helm upgrade to performing create and patch API requests based on the
JSON Patch data.

Doing this is much lighter than performing a full release cycle, and
deals with the issue of Helm being unable to restore state of Custom
Resources without the `--force` flag being set. Which has unwanted
side-effects like forcing objects through a deletion/creation cycle.

After a drift correction attempt a Kubernetes Event is emitted, which
contains a summary of the created and patched resources, and a
collection of any (potential) errors.

As the goal is to restore state as best as we can, the drift correction
will be re-attempted until all resources have been restored to the
desired state.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-29 20:34:45 +01:00
Stefan Prodan 113bf544d3
Merge pull request #821 from fluxcd/deprecate-v2beta1
Add deprecation warning to v2beta1 API
2023-11-27 16:53:35 +02:00
Stefan Prodan 92a535f6cd
Add deprecation warning to v2beta1 API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-11-27 16:41:50 +02:00
Hidde Beydals e0ecb05099
Merge pull request #820 from fluxcd/dependabot/github_actions/ci-9cf97fb57d
build(deps): bump the ci group with 3 updates
2023-11-27 09:52:36 +01:00
dependabot[bot] 4e59953180
build(deps): bump the ci group with 3 updates
Bumps the ci group with 3 updates: [anchore/sbom-action](https://github.com/anchore/sbom-action), [fossa-contrib/fossa-action](https://github.com/fossa-contrib/fossa-action) and [github/codeql-action](https://github.com/github/codeql-action).


Updates `anchore/sbom-action` from 0.14.3 to 0.15.0
- [Release notes](https://github.com/anchore/sbom-action/releases)
- [Commits](78fc58e266...fd74a6fb98)

Updates `fossa-contrib/fossa-action` from 2.0.0 to 3.0.0
- [Release notes](https://github.com/fossa-contrib/fossa-action/releases)
- [Changelog](https://github.com/fossa-contrib/fossa-action/blob/master/CHANGELOG.md)
- [Commits](6728dc6fe9...cdc5065bcd)

Updates `github/codeql-action` from 2.22.7 to 2.22.8
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](66b90a5db1...407ffafae6)

---
updated-dependencies:
- dependency-name: anchore/sbom-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: ci
- dependency-name: fossa-contrib/fossa-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: ci
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: ci
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-27 03:28:56 +00:00
Hidde Beydals 6ec21aba4a
Merge pull request #818 from fluxcd/allow-digest-config
Allow configuration of snapshot digest algorithm
2023-11-24 18:33:00 +01:00
Hidde Beydals 7a70bd599f
Allow configuration of digest algorithm
This introduces a `--snapshot-digest-algo` flag to allow configuring a
different algorithm than SHA256.

This allows the user to for example configure `blake3`, which is
potentially faster (and less resource intensive) on modern hardware.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 18:19:53 +01:00
Hidde Beydals f7185d4c62
Merge pull request #819 from fluxcd/tidy-code
Remove obsolete code and tidy things
2023-11-24 18:19:42 +01:00
Hidde Beydals 841fca08fe
features: mark drift related flags as deprecated
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 18:01:07 +01:00
Hidde Beydals 2d927b9b9e
Miscellaneous tidying of minor things
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 17:59:45 +01:00
Hidde Beydals 0d30be93ec
Remove various verification functions
These functions are no longer in use by the actual code base, while the
same outcome can be achieved by using `LastRelease` in combination with
`VerifyReleaseObject`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 17:59:44 +01:00
Hidde Beydals 347cf24482
Remove obsolete `util` package
This code is now available in upstream controller-runtime.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 17:59:42 +01:00
Hidde Beydals be2c47e3b4
Remove obsolete `runner` sub-module
This used to drive the logic behind the `v2beta1` API, but has now
become obsolete with the `action` sub-module as its successor.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 17:59:39 +01:00
Hidde Beydals 85cac772eb
Merge pull request #815 from fluxcd/new-drift-detection
Allow configuration of drift detection on `HelmRelease`
2023-11-24 17:59:34 +01:00
Hidde Beydals 6b1effcd2f
diff: remove `Differ` code
In favor of the new `Diff` action.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 16:41:47 +01:00
Hidde Beydals bb6ad72654
reconcile: determine drift in cluster
This allows `DetermineReleaseState` to determine if the cluster state
has drifted from the manifest defined in the Helm storage. This allows
the atomic reconciler to determine if an upgrade should happen based
on the configuration of the `HelmRelease`.

If drift detection is `enabled` (or set to `warn`), it will report
drift via the controller logs and a Kubernetes Event. In addition, when
correction is enabled, it will instruct to perform a Helm upgrade to
correct the drift.

To summarize the detected drift in a compact message, summarize
utilities have been introduced to the `diff` package.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 16:41:45 +01:00
Hidde Beydals 98c4118818
action: introduce `Diff` action
The `Diff` action can be used to detect changes between the manifest
from a Helm release and the current cluster state.

Compared to the previous diff functionality, it allows for ignoring
specific fields in a resource using the newly introduced ignore rules
in the API.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 13:35:15 +01:00
Hidde Beydals a5db99a88c
api: allow configuration of drift detection
This adds the option to enable drift detection for a specific
`HelmRelease` instance using `.spec.driftDetection.mode`.

Supported configurations are `enabled` (detect and correct), `warn`
(detect) and `disabled`.

In addition to this, it allows defining a set of ignore rules using
`.spec.driftDetection.ignore`. Which can be used to ignore (portions
of) a resource using JSON pointers and target selectors.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 13:33:32 +01:00
Hidde Beydals c3f13a3844
Merge pull request #817 from fluxcd/update-k8s
Update to Kubernetes 1.28.x, Helm v3.13.2 and Kustomize v5.2.1
2023-11-24 13:32:33 +01:00
Hidde Beydals e441c251c3
api: change `yaml` field tag to `json`
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 13:19:34 +01:00
Hidde Beydals 576c14e272
reconcile: slightly change "unmanaged" log message
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 12:52:17 +01:00
Hidde Beydals 6654b347fe
release: remove `Labels` field from `Observation`
Helm v3.13.x includes a change which causes labels to be magically
set during writes to the storage, without persisting them to the
release object which is passed to the interface.

Because of this, at the time of observing the initial write to the
storage we would not see them, but once we are verifying them we would.
Causing the calculated digest to always differ, and making the
controller think the storage item had changed.

While I am of opinion it would be better for Helm to set the labels on
the release object as soon as they are persisted to the storage, the
only solution now for us is to ignore them.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 12:47:24 +01:00
Hidde Beydals fb6221c4a3
yaml: adopt for `sigs.k8s.io/yaml` `v1.4.0`
Due to switch to a hard fork of goyaml.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 12:46:34 +01:00
Hidde Beydals eaa2a8c2fe
Update dependencies
- github.com/fluxcd/cli-utils to v0.36.0-flux.1
- github.com/fluxcd/pkg/apis/event to v0.6.0
- github.com/fluxcd/pkg/apis/kustomize to v1.2.0
- github.com/fluxcd/pkg/apis/meta to v1.2.0
- github.com/fluxcd/pkg/runtime to v0.43.0
- github.com/fluxcd/pkg/ssa to v0.34.0
- github.com/fluxcd/pkg/testserver to v0.5.0
- github.com/go-logr/logr to v1.3.0
- github.com/google/go-cmp to v0.6.0
- github.com/hashicorp/go-retryablehttp to v0.7.5
- github.com/onsi/gomega to v1.30.0
- github.com/opencontainers/go-digest to v1.0.1-0.20231025023718-d50d2fec9c98
- github.com/opencontainers/go-digest/blake3 to v0.0.0-20231025023718-d50d2fec9c98
- golang.org/x/text to v0.14.0
- helm.sh/helm/v3 to v3.13.2
- k8s.io/api to v0.28.4
- k8s.io/apiextensions-apiserver to v0.28.4
- k8s.io/apimachinery to v0.28.4
- k8s.io/cli-runtime to v0.28.4
- k8s.io/client-go to v0.28.4
- k8s.io/kubectl to v0.28.4
- k8s.io/utils to v0.0.0-20231121161247-cf03d44ff3cf
- sigs.k8s.io/controller-runtime to v0.16.3
- sigs.k8s.io/kustomize/api to v0.15.0
- sigs.k8s.io/kustomize/kyaml to v0.15.0
- sigs.k8s.io/yaml to v1.4.0

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 12:43:33 +01:00
Hidde Beydals a97a9ffa69
api: update dependencies
- github.com/fluxcd/pkg/apis/kustomize to v1.2.0
- github.com/fluxcd/pkg/apis/meta to v1.2.0
- k8s.io/apiextensions-apiserver to v0.28.4
- k8s.io/apimachinery to v0.28.4
- sigs.k8s.io/controller-runtime to v0.16.3
- sigs.k8s.io/yaml to v1.4.0

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 11:21:36 +01:00
Hidde Beydals 3f431e1cc8
Merge pull request #816 from fluxcd/test-suite-fixes
Address minor issues
2023-11-24 11:04:02 +01:00
Hidde Beydals e4d19b8e89
testdata: properly take tag value into account
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 10:47:02 +01:00
Hidde Beydals 4c439b721a
action/upgrade: use correct CRD policy
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 10:46:23 +01:00
Hidde Beydals 001e7da2f1
controller: repair fuzz test
We should actually add more of them now that the code base has grown (in
complexity). But this solves the issue for CI for now.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-24 10:11:33 +01:00
Hidde Beydals b8d65235f8
Merge pull request #738 from fluxcd/new-reconciler
Rework `HelmRelease` reconciliation logic
2023-11-24 09:39:01 +01:00
Hidde Beydals 4a8d2ff0f4
action: provide reason for failures count reset
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:17 +01:00
Hidde Beydals 3ce6e8d1b5
reconcile: improve wording `Stalled` condition
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:17 +01:00
Hidde Beydals 0535ae1114
predicates: notice source changing to `Ready=True`
This ensure that when a chart object has a temporary `Ready=False`
state, the predicate will notice the change to `Ready=True` and
cause an enqueue request.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:16 +01:00
Hidde Beydals 6ffdaddc06
action: omit logging on CRD apply no-op
As it does not offer real value, and creates noise when the logs are
included in an emitted event.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:15 +01:00
Hidde Beydals 7aad010664
controller: immediate requeue unfinished release
This improves continuity while the controller attempts to move the
release forward.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:14 +01:00
Hidde Beydals 5d1f34a029
controller: patch after setting `Reconciling=True`
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:13 +01:00
Hidde Beydals 20c00fd47a
action: provide a reason on release target changes
This to allow better feedback to the user on why the controller decided
to uninstall the release.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-23 00:17:09 +01:00
Hidde Beydals 580c72cd09
controller: adopt release based on v2beta1 state
This allows the controller to be updated from `v2beta1` to `v2beta2`
without triggering a release to settle state.

It does this by looking at the previous successful release as recorded
for the `v2beta1` object, and if found, recording a snapshot for it in
the new `History` field of the status.

This feature can be disabled by setting the `AdoptLegacyReleases`
feature flag to `false`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-22 23:14:17 +01:00
Hidde Beydals eab8a50071
api: prepare `v2beta1` status for `v2beta2`
This allows users to delay updating their `apiVersion` declarations,
as the fields will be known in the previous version.

If we would not do this, the fields would get wiped when the `v2beta1`
resource is applied, potentially causing spurious upgrades.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-22 23:14:15 +01:00
Hidde Beydals 9bb8f02495
api: continue to record `LastAppliedRevision`
This ensures that certain UIs can continue to display information to
their users while they work on making better use of the new data
available in `v2beta2`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-21 15:31:30 +01:00
Hidde Beydals 6f05228e85
reconcile: remove logs from test failure event
During tests, Helm logs a mixture of debug and timeout errors which
(unlike during install or upgrade) do not provide much useful
information about the reason of failure.

Given this, remove the logs from the output to reduce noise.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-20 12:06:56 +01:00
Hidde Beydals 28a7800528
reconcile: mark `Ready=Unknown` when awaiting test
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-20 12:06:55 +01:00
Hidde Beydals 70485017d2
controller: requeue on fixed interval on chart 404
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-20 12:06:54 +01:00