Commit Graph

43 Commits

Author SHA1 Message Date
Kaden Nelson 518a846596
Add a finalizer to the ImagePolicy and ImageRepository resources
Fixes https://github.com/fluxcd/image-reflector-controller/issues/225

This PR adds a finalizer to the ImagePolicy and ImageRepository resources. This is to properly record the Deleted reconciliation status when the object is deleted from the cluster. Without this change, the resource would be deleted before the image reflector controller has a chance to properly report the resource's status in the metrics. As a result, end-users may see falsely reported metrics.

Signed-off-by: Kaden Nelson <kaden_l_nelson@apple.com>
2022-06-24 10:57:19 +03:00
Sunny b696275eb6
use new standardized runtime and meta package
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-03-18 00:10:18 +05:30
Sanskar Jaiswal 7b53e9f72e Refactor logging to be more consistent.
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-02-15 19:18:51 +05:30
Michael Bridgen 48a673d345 Add --no-cross-namespace-refs flag
This uses the helper in fluxcd/runtime/acl to bind the cross-ns flag,
passes it to the controller, and checks it when resolving the
potentially cross-namespace reference.

Signed-off-by: Michael Bridgen <michael@weave.works>
2022-01-27 17:20:35 +00:00
Michael Bridgen 42aa8ed657 Use fluxcd/pkg/{apis,runtime}/acl for ACLs
This commit replaces the local ACL-related API types, and the func for
checking access, with their standarised forms in fluxcd/pkg/apis/acl
and fluxcd/pkg/runtime/acl respectively.

The test case for "When the ACL is empty, it denies access" needed
adjustment because the zero value of acl.AccessFrom is not valid -- it
needs an explicit list of namespace selectors. Providing `nil` in the
test case is the equivalent of providing a zero value.

Signed-off-by: Michael Bridgen <michael@weave.works>
2022-01-27 17:20:27 +00:00
Aurel Canciu 8a46f14552
Update flux pkg components
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2022-01-06 23:11:14 +01:00
Aurel Canciu 68f7a60db0
Fix watched same-ns image repos trigger reconcile
Fixes a regression introduced in v0.13.1

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-11-11 21:55:59 +01:00
Aurel Canciu 006f204aaa
Update ImagePolicy index imageRepoKey include ns
The imageRepoKey only contains the name of the ImageRepository resource.
This change uses the namespaced name to avoid collisions.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-11-11 15:36:55 +01:00
Aurel Canciu 0dd4f706ff
Watched cross-ns image repos trigger reconcile
Cross-namespace ImageRepository resources should trigger reconciles for
ImagePolicies that refer to them. Previously, this was only done for
resources in the same namespace.

Fixes #195

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-11-11 15:20:50 +01:00
Sunny 5e7312d574 policy: Handle failure due to invalid semver range
This adds error check after creating a Policer.
For alphabetical and numerical policies, the k8s API validates the
input data. But for semver policy, there aren't predefined valid
values.

Adds a test to verify the fix.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2021-09-20 20:41:57 +05:30
Stefan Prodan 3f77178a87
Clarify access from all namespace
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-06 17:34:32 +03:00
Stefan Prodan 8f4ae31562
Add test for empty label selector and fix ACL name
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-06 16:44:37 +03:00
Stefan Prodan 9126625713
Use the metav1 label selector helpers in ACL logic
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-06 14:57:30 +03:00
Stefan Prodan eb61ba0000
Implement access control list for repository
When a policy refers to a repository in a different namespace, the controller checks if the policy namespace labels match any of the selectors defined on the ImageRepository object. If the namespace where the policy resides, doesn't have labels or the labels don't match the repository ACL, then the controller sets the policy ready status to false and the reason to AccessDenied. The access denied error message is set on the ready condition message and logged before the controller rejects the policy.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-06 12:03:06 +03:00
Michael Bridgen 58e7a1539d Graduate v1alpha2 API to v1beta1
The schema is the same, which means this is a case of

 - copying over the type definitions;
 - changing the "stored" CRD version;
 - giving a CRD conversion of None, meaning just change the apiVersion;
 - using the new API package in the controller code;
 - moving the API docs to v1beta1

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-06-24 15:50:11 +01:00
Max Jonas Werner 03043e592e
chore: add options type for both controllers
This is in alignment with other controllers such as the
helm-controller.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2021-06-24 16:22:07 +02:00
Max Jonas Werner f78b99301b
Make concurrent reconciliation configurable
Default for both, the ImageRepository and the ImagePolicy controllers
is 4 workers.

closes #148

Signed-off-by: Max Jonas Werner <mail@makk.es>
2021-06-23 17:05:03 +02:00
Aurel Canciu 746f61edb3
Better error reporting for image policy evaluation
A more verbose message associated with the error should give the user
better understanding of the cause and the nature of the failure.

Fixes #143

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-05-14 20:05:54 +03:00
Aurel Canciu 6ffbfa67c2
Ensure invalid regex errors are reported to user
The errors generated by ImagePolicy resources having invalid tag filter
regex patterns were not being reported to the user correctly, no event
was recorded and the ReadyCondition message did not reflect the
encountered error.

Fixes #138

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-04-29 00:26:36 +03:00
Michael Bridgen ced5d88fe6 Move from v1alpha1 to v1alpha2 API
The image automation part of the API has changed structure (see [1]),
and had a version bump from `v1alpha1` to `v1alpha2`. Since the types
here are also in `image.toolkit.fluxcd.io`, there will be less
complication if they also get a version bump even though they aren't
changing.

[1] https://github.com/fluxcd/image-automation-controller/pull/139

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-21 15:58:59 +02:00
Stefan Prodan 43f06484fa
Use patch instead of update to set status
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-04-21 13:22:28 +03:00
Aurel Canciu cbcad122f9
Implement policy-level tag regex filtering
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2021-01-13 16:42:40 +02:00
Hidde Beydals 6283fbb3da 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.
- 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
  `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.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-13 12:34:28 +01:00
Aurel Canciu 9be3bc2325
Implement Alphabetical order policy
This implementation allows one to set a `MatchTagPrefix` to filter a
list of tags and/or use `Order` to set the ordering rule by which tags
are evaluated.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-12-09 21:02:42 +02:00
Kevin McDermott da2b9e6746 Add BadgerDB as a persistent store for the tag data.
This introduces a key/value store for tags, with the keys being the
images and the values being JSON encoded versions of the tags.

The Badger data is stored in a PVC.

Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
2020-12-09 13:53:11 +00:00
Michael Bridgen ab07353ec5 Register a status if there's no latest image
Previously the image policy controller, having worked through all the
preliminaries, would record a latest image if it found one, but
otherwise remain silent.

However, we also want to know if there _wasn't_ a latest image. So,
record a status in that case too.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-04 12:11:40 +00:00
Michael Bridgen 379f2822db Give ImagePolicy objects a readiness condition
This adds the conventional Conditions field to the ImagePolicy status,
and sets the status in the controller as well as reporting readiness
metrics.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-04 12:11:40 +00:00
Aurel Canciu 096e51986c
Use pkg/version to parse versions
Fixes #38

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-25 17:45:51 +02:00
Aurel Canciu e964198b28
Implement metrics recording
Record readiness condition in imagerepository controller

Fixes #55

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-25 17:45:44 +02:00
Aurel Canciu 9b0c828d76
Implement event notifications using pkg/runtime
Fixes #50

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-24 18:52:03 +02:00
Hidde Beydals 5dc1587613 Change copyright to Flux authors
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-27 18:03:38 +01:00
stefanprodan 0df16f7735 Configure events dispatching 2020-08-11 11:19:03 +03:00
stefanprodan 3c24b2dd43 Configure JSON logging 2020-08-11 09:04:02 +03:00
Michael Bridgen 6f46cbb331 Change go module and rewrite imports 2020-08-10 16:10:50 +01:00
Michael Bridgen f0991c829b Reassign copyright to Flux project 2020-08-10 16:07:09 +01:00
Michael Bridgen 949f5815f1
Merge pull request #18 from squaremo/update-controller-runtime
Update controller runtime to 0.6.2, go to 1.14
2020-08-06 09:46:21 +01:00
Michael Bridgen 4acc833a86 Bump controller-runtime to 0.6.2
This brings k8s/client-go, apimachinery, and so on up to 0.18 as a
consequence.

This commit also makes the version of the temporary (in case of it not
being on the path) controller-gen tool, to 0.3.0.
2020-08-05 20:50:00 +01:00
Michael Bridgen 7ab3632b1b Rename ImageRepository -> ImageRepositoryRef
.. to follow gitops-toolkit convention.
2020-08-05 19:58:57 +01:00
Hidde Beydals c590c94ec1 Change CRDs domain to 'image.toolkit.fluxcd.io' 2020-07-31 15:03:28 +02:00
Michael Bridgen 143d53dc32 Update module and imports 2020-07-18 15:12:14 +01:00
Michael Bridgen e0e1491970 Recalculate policy when a repository changes
This adds a watch for ImageRepository so that policies will be
recalculated when the repository is scanned.
2020-07-14 12:34:30 +01:00
Michael Bridgen a2b0bd4ed7 Calculate latest image for (semver) policy
This adds the details of calculating the latest image for a policy. It
relies on the ImageRepository and ImagePolicy controllers having a
shared database of image tags. Usually, this sort of thing would be
objects in the Kubernetes database; but since tags (and images) can
number in the tens of thousands per image, I'm using a separate
database. For the minute, it's just a map.
2020-07-14 12:34:30 +01:00
Michael Bridgen 6658e4926a Add ImagePolicy type
kubebuilder create api --group image --version v1alpha1 --kind ImagePolicy
2020-07-12 18:30:19 +01:00