Commit Graph

56 Commits

Author SHA1 Message Date
Matheus Pimenta 07058a1f60
[RFC-0010] Introduce feature gate
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2025-05-19 13:44:48 +01:00
Matheus Pimenta 41a0e4d324
Enable token cache by default
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2025-05-03 10:34:26 +01:00
Matheus Pimenta 8414fa2aa0
Introduce token cache and use it for GitHub App tokens
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2025-03-12 14:47:30 +00:00
Sunny edc5cee43d Add new reconciler using new v1beta2 API
Introduce the rewritten reconciler which uses v1beta2 API and the new
internal/policy and internal/source packages for performing all the
operations. The reconciliation model is written similar to the other
flux controller, with simplified events and logs, and kstatus support.
The reconciliation result computation similar to
image-reflector-controller, using the same reconciler helpers from
pkg/runtime repo.

With the new status fields ObservedPolicies and ObservedSourceRevision,
the reconciler now avoid full sync of the source which involves cloning
the source every time. If the policies and the remote source have not
changed since the last reconciliation, the reconciliation is returned
early without cloning and apply the updates. This is only applicable
when the checkout branch and the push branch are the same. For a
different push branch and refspec, full sync is always performed as
before.

Notifications are now only sent when there's something new to inform
about. If there is no change, an source up-to-date notification is sent.
When there's an update, the details about the pushed commit with any
rendered commit template is send. When there's a failure, the error is
sent in the notification. And when there's an error recovery, a success
notification is sent to rely that the automation has recovered.

Signed-off-by: Sunny <github@darkowlzz.space>
2024-04-18 16:16:09 +05:30
Stefan Prodan f88fe3d441
Migrate to controller-runtime v0.16
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-11-20 23:18:32 +02:00
Sunny e27a9e2482
Delete stale metrics on object delete
The metrics helper now accepts owned finalizers to determine if an
object is no longer managed by the controller and is being deleted, and
deletes the metrics associated with the object.

Call the metrics recording defer function in controller early to be able
to record the object in deleting state.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-08-11 19:46:58 +05:30
Hidde Beydals bfb2a978ad Set controller package name
Set package name in the files under internal/controller to have the
base name of the directory.

This style is recommended by Go, and certain text editors/IDEs get
confused when the names don't match.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-31 13:15:46 +02:00
Hidde Beydals 7cc9c9c5f4 Rename controllers to controller
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-25 10:08:03 +02:00
Hidde Beydals c65a2dfeea Update ctrl-runtime (v0.15), Kubernetes (v1.27), kyaml (v5)
This 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.
- Fake clients used in tests are now configured using
  `WithStatusSubresource` to enable the correct behavior for status
  updates and patches.
- Max concurrent reconciles and panic recovery 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 are
updated to their latest (compatible) versions as well. Including an
update of kyaml to match Kustomize v5.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-25 10:08:03 +02:00
Max Jonas Werner dfe26820d9
bump API deps; GitRepository v1
Signed-off-by: Max Jonas Werner <mail@makk.es>
2023-03-31 14:27:12 +02:00
Max Jonas Werner 8760b2140d
Add reconciler sharding capability based on label selector
The new `--watch-label-selector` lets operators provide a label to the
controller manager which in turn uses it to reconcile only those resources
`ImageUpdateAutomations` that match the given label.

This way operators can deploy multiple instances of IAC, each reconciling a
distinct set of resources based on their labels and effectively scale IAC
horizontally.

closes #503

Signed-off-by: Max Jonas Werner <mail@makk.es>
2023-03-31 12:42:49 +02:00
Sanskar Jaiswal c62e9f289c move `controllers` to `internal/controllers`
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-03-27 22:33:01 +05:30
Hidde Beydals 4994c9fbc1
Use `logger.SetLogger` to also configure `klog`
This uses the newly introduced helper from runtime, which also
configures the logger for `klog`.

Resulting in all logs now being properly formatted, even when logged by
internal Kubernetes elements like the leader election or a dynamic
client.

The update from `fluxcd/pkg/runtime` from `v0.29.0` to `v0.31.0` in
addition includes a change which configures the event recoder to only
log on level `trace` (as opposed to `debug`).

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-03-08 11:04:27 +01:00
Sunny b270f945c4 Update image-reflector API to v1beta2
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-02-16 22:37:26 +05:30
Sunny 4be070b871 Disable caching of Secrets and ConfigMaps
Disable caching of Secrets and ConfigMaps by default. Enable caching
using feature gate.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-01-30 21:22:23 +05:30
Paulo Gomes 7a05f4856c
libgit2: Remove references to libgit2 from code
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-12-09 11:30:55 +00:00
Paulo Gomes 0191d6b4cc
gogit: Add new ForceGoGitImplementation FeatureGate
ForceGoGitImplementation ignores the value set for gitImplementation
and ensures that go-git is used for all GitRepository objects.
This can be used to confirm that Flux instances won't break if/when
the libgit2 implementation was to be deprecated.

When enabled, libgit2 won't be initialized, nor will any git2go cgo
code be called.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-11-04 11:16:26 +00:00
Sanskar Jaiswal 0296f7acf0
refactor reconciler to use fluxcd/pkg/git
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-10-27 14:42:13 +01:00
Paulo Gomes 06f4acd118
Use helper.Metrics for recording metrics
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-09-05 14:03:08 +01:00
Paulo Gomes 0fdcf7fe6d
Enable RecoverPanic
The controller-runtime provides the ability to recover from
panics that have arisen from a reconciliation. This change
enables this functionality by default.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-08-10 09:59:19 +01:00
Paulo Gomes 4a8ddfad49
git: Decommission libgit2 Unmanaged Transport
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-08-09 13:47:48 +01:00
Paulo Gomes ec89ad41b9
Update source-controller to v0.25.7
This version of source-controller introduces a fix for the
SSH connections leak issue reported at:
https://github.com/fluxcd/image-automation-controller/issues/334

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-22 15:55:50 +05:30
Paulo Gomes d46a42e198
Add new flag --ssh-hostkey-algos
The new flag allow users to set the list of hostkey algorithms
to use for ssh connections, enabling them to ensure specific
are/aren't used.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-12 10:44:02 +01:00
Paulo Gomes 31fe65346a
git: Enable managed transport by default
GitManagedTransport enables the use of Managed Transport. This replaces
the previous 'EXPERIMENTAL_GIT_TRANSPORT' environment variable that was
used for the same result. This commit also enables it by default.

This is an opt-out feature, which can be disabled by starting the
controller with the argument '--feature-gates=GitManagedTransport=false'.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-01 21:03:54 +03:00
Sanskar Jaiswal dfa62d22e9 add flag to allow configuration of ssh kex algos
Signed-off-by: Sanskar Jaiswal <sanskar.jaiswal@weave.works>
2022-04-14 04:05:18 +05:30
Paulo Gomes 4a53f9defa
Add flags to configure exponential back-off retry
Add two new flags to enable users to configure exponential
back-off for Flux objects. The default values are now
set to 750ms for minimum retry time, and 15min for max.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-12 13:01:36 +01:00
Paulo Gomes 859a6ca93a
Update source-controller to v0.22.4
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-28 15:22:19 +01:00
Paulo Gomes 5b15bb7f94
Implement Managed Transport for libgit2
libgit2 network operations are blocking and do not provide timeout nor context capabilities,
leading to several reports of the controllers hanging indefinitely.

By using managed transport, golang primitives such as http.Transport and net.Dial can be used
to ensure timeouts are enforced.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-21 15:19:00 +00:00
Sunny 146a86865c Use new standardized runtime and meta package
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-03-21 12:45:55 +01:00
Somtochi Onyekwere 0ca01bd254 Add flag to disable cross-namespace referencing
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2022-01-28 08:32:21 +01:00
Michael Bridgen fd52463ac5 Use v1beta1 of the API from image reflector
This bumps the version of the image reflector types to v1beta1. This
doesn't technically make a difference for the minute, since the
Kubernetes API server would convert between versions, but is tidier.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-06-28 13:59:34 +01:00
Michael Bridgen 5b9631327f Graduate v1alpha2 API to v1beta1
This does the following:

 - copies the type definitions from v1alpha2 to v1beta1
 - changes the "stored" version to v1beta1
 - gives the CRD a conversion strategy of None, meaning just rewrite the version
 - switches the controller to use v1beta1
 - moves the generated documentation to v1beta1

This effectively rebadges the v1alpha2 version of this part of the
image API to v1beta1. The v1alpha2 version is left in place; there are
no conversion issues, as with v1alpha1->v1alpha2. The CRD specifies
that converting between v1alpha2 and v1beta1 just means changing the
version (i.e., the schema and semantics are the same).

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-06-28 11:26:59 +01:00
Max Jonas Werner 93782755ef
feat: add controller concurrency
The controller is now working with 4 concurrent workers by default.
This value is configurable through the `--concurrent` flag.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2021-06-24 20:15:00 +02:00
Stefan Prodan 833b50fdee
Move to ImagePolicy v1alpha2
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-04-22 10:03:22 +03:00
Michael Bridgen cd8a2e97b8 Flip the controller and tests to API v1alpha2
This finishes the v1alpha2 API, and rewrites everything needed so that
the controller supports it and the tests pass. For the most part, that
is just changing the location of fields. However, there's a few
notable extras:

 - check that the `sourceRef` is a git repo (that's the default), and
   that a `.spec.git` is supplied;

 - change a test that blindly patched an update object, so that it
   first gets the object it's patching. Previously, it succeeded
   because it was OK to patch everything to empty strings, but that's
   no longer the case since SourceReference.Kind is an enum.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-13 10:45:58 +01:00
Michael Bridgen f28a0c40ff Add v1alpha2 API version
This adds a v1alpha2 API, without changing the controller or tests to
use it (yet). The new API has roughly the desired shape, per
https://github.com/fluxcd/flux2/discussions/1124, but supporting only
things that the controller supports now.

It's necessary to give the v1alpha1 type a `storageversion` marker so
that 1. code generation keeps working, and 2. tests still work, since
they still expect v1alphav1 types. v1alpha1 will be removed once the
controller and tests are ported to v1alpha2.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-13 10:30:51 +01:00
Stefan Prodan 299d874b9e
Use controller name in LeaderElectionID
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-25 14:22:02 +02:00
Stefan Prodan cdd4cb03f6
Set leader election deadline to 30s
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-25 14:04:15 +02:00
Hidde Beydals 3ee2f904e1 Enable pprof endpoints on metrics server
Using the helper from `pkg/runtime/pprof`, which follows the suggestion
from controller-runtime to use `AddMetricsExtraHandler`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-02-07 12:52:14 +01:00
Stefan Prodan f5a8b922b9
Update fluxcd/pkg/runtime to v0.8.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-01-21 19:57:12 +02:00
Hidde Beydals 0531deaaed 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.2 to include `controller-runtime` changes.
- Logger has been removed from the reconciler, and is 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
  `ReconcileRequestedPredicate`, 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:

- Upgrade of `image-reflector-controller` API package to include
  controller-runtime changes.
- Upgrade of `source-controller` API package to v0.6.1.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-14 13:48:37 +01:00
Michael Bridgen 64177cc6f5 Send notifications too when emitting events
This adds the external event recorder (a.k.a., notifications client)
to the reconciler, and expands the definition of
`<reconciler>.event(...)` so that it will send a notification whenever
an event is emitted. This is the conventional way of handling events
amongst the GitOps Toolkit controllers.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-01 11:37:23 +00:00
Michael Bridgen 31f1e62cd4 Use probes installer from fluxcd/pkg
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-01 11:28:06 +00:00
Michael Bridgen 16e810a123 Record metrics for readiness and duration
Using the conventions of the day.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-01 11:08:29 +00:00
Michael Bridgen 311ca212c5 Give controller liveness and readiness endpoints
- make the healthz endpoint a flag and give the value to the
   controller runtime
 - set up probe endpoints; copy the func from elsewhere for now
 - add the probe defs to the deployment

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-23 13:44:12 +00:00
Michael Bridgen 5bd0bc8cba Set logger up with log level and JSON flags
This is the GitOps Toolkit convention.  This commit also puts the
flags in the base deployment config, in the same order as for other
GOTK controllers.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-23 12:54:15 +00:00
Michael Bridgen 59975f6ad0 Make room for event recorder
This gives the controller an event recorder, without using it yet, and
makes sure it is registered when setting everything up in main.go.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-23 11:23:30 +00:00
Michael Bridgen 385277bef3 Add --watch-all-namespaces flag to controller
This is a convention among the GitOps toolkit controllers; if false,
the controller will watch only resources in the namespace in which
it's running.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-23 11:08:05 +00:00
Hidde Beydals bf8c2deeb7 Make the API package a dedicated module
This includes changes to:

* Bump the Kubernetes dependencies to v1.19.3 to align
  with the other toolkit controllers.
* Update controller-runtime dependency to v0.6.3 to align
  with the other toolkit controllers.
* Update the source-controller dependency to the most recent
  v0.2.2 version to include the v1beta1 API.
* Add the `pkg/gittestserver` dependency for the Git tests,
  as this package was removed in a newer source-controller version.
* Bump the Go version to v1.15.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-19 12:16:17 +01:00
Hidde Beydals 29c60ecc6e Change copyright to Flux authors
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-27 17:57:31 +01:00