Commit Graph

29 Commits

Author SHA1 Message Date
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 eb9c0c8d86 Omit suspended objects from metrics
The convention appears to be to not record any metrics for objects
that are suspended (unless they are also being deleted).

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-03 11:49:46 +00:00
Michael Bridgen e6de16930a Make the ImageRepositoryStatus empty when empty
The zero value of an ImageRepositoryStatus includes a struct value in
LastScanResult, which prevents it from being omitted when
serialised. The effect is that a freshly-constructed ImageRepository
will serialise like this:

```yaml
apiVersion: image.toolkit.fluxcd.io/v1alpha1
kind: ImageRepository
metadata:
  name: foobar
  namespace: flux-system
spec:
  image: alpine
  interval: 1m0s
status:
  lastScanResult:
    tagCount: 0
```

This commit changes the LastScanResult field to a pointer
type, so it can be `nil` when not set.

The ScanTime field is changed from a pointer to a value, since it
should be present in any scan result.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-03 11:43:26 +00: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
Aurel Canciu 5eec08d232
Refactor and align with stable components patterns
This is an attempt to bring the api and controller logic closer to what
the other controller components already have set as patterns.

1. Adopt the k8s standard Condition type.
2. Rename `ScanInterval` to `Interval` to be consistent with the
   `Interval` attribute other Spec types have defined, translating to
   reconciliation interval. This attribute is now required.
3. Add `ScanTime` attribute to the `ScanResult` type, enabling keeping
   track of the last successful scan execution. Use this value for scan
   frequency throttling.
4. Add optional `Timeout` attribute to allow custom scan timeout
   handling. The default value is equal to that of the `Interval` attr.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-23 20:38:54 +02:00
Aurel Canciu ba7800eaf6 Adopt k8s standardized conditions
Use the newly introduced standardized Condition type kubernetes/enhancements#1624

Relates to fluxcd/flux2#225

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-12 10:44:57 +00:00
Michael Bridgen 2a630205e2 Get and use credentials from secret if given
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-10 21:15:23 +00: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
Michael Bridgen 15652779f1 Use reconcile annotation helpers 2020-10-22 10:33:45 +01:00
Michael Bridgen 316b9758c4 React to a change in the reconcileAt annotation
Despite the name, the contract of the reconcileAt mechanism is that
_changing it_ should trigger reconciliation outside the otherwise
specified schedule. To detect changes, this commit adds a field to the
status, and updates it when a scan has run.
2020-10-20 14:09:31 +01:00
Michael Bridgen 4e5c89ae18 Respect the reconcileAt annotation
The GOTK controllers all use an annotation to trigger syncing outside
of the schedule (e.g., when a webhook is indicates a new
revision). This commit makes the ImageRepository controller respect
the annotation, by checking it when examining an image repo object.

This works a little different to the other controllers, which tend to
assume that any incoming event means a sync is due. The image
reflector controller uses the ChangedPredicate to filter incoming
evetns, as they do, but goes further to check the annotation and
otherwise, the scheduled scan time.
2020-10-19 13:52:36 +01:00
Kevin McDermott 4c0f6d69be Add support for suspending image scans.
Co-authored-by: Michael Bridgen <mikeb@squaremobius.net>
2020-08-28 11:45:27 +01:00
Michael Bridgen 155f6e948d Be consistent about returning an error
It's mooted in https://github.com/fluxcd/toolkit/discussions/164 that
a distinct metric is used for not completing reconciliation, as
opposed to an unexpected error. Until that discussion has run its
course, we should just do what the other controllers do, and that's
returning an error when the controller is unable to reconcile to
completion.

This also adds a comment noting the purpose of the redundant `Requeue:
true` fields, for the avoidance of confusion later.
2020-08-20 14:45:43 +01:00
stefanprodan 4a546eb97c Add image URL invalid reason 2020-08-15 08:38:57 +03:00
stefanprodan d966c16a06 Implement Ready condition for image repos 2020-08-12 16:38:43 +03: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
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 6ae6561b8b Test that the tags for a repo are scanned
In this commit I use the test registry implementation to check that
the controller will scan the tags of an image. This needs a bit more
scaffolding, since the test registry doesn't handle /tags/list.
2020-07-12 14:08:16 +01:00
Michael Bridgen c9c5c4ad63 Actually scan the image repository
This commit adds a little code to scan the image repository given in
an ImageRepository resource, and report the (number of) tags there. It
does so anonymously, so it'll only work for public repos for the
minute.

The next step is to introduce ImagePolicy resources and figure out the
interaction with them -- e.g., if they only care about semver, you
might only need to get the tags.
2020-07-11 09:37:45 +01:00
Michael Bridgen 91c342d288 Jiggle things around until there's a passing test 2020-07-09 21:20:04 +01:00
Michael Bridgen 777ec34a86 Implement minimal ImageRepository spec
This adds an image name to the ImageRepository type, and resolves it
in the controller, just to show it doing something.
2020-07-08 22:13:35 +01:00
Michael Bridgen a628d482d5 Add ImageRepository type
kubebuilder create api --group image \
      --version v1alpha1 --kind ImageRepository
2020-07-08 07:49:00 +01:00