Commit Graph

49 Commits

Author SHA1 Message Date
Hidde Beydals aad03ca025 Update source-controller/api to v0.13.0
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-05-26 15:04:20 +02:00
Stefan Prodan c71ea97d62
Release v0.9.1
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-05-06 16:26:03 +03:00
Stefan Prodan 9e7111be0f
Update source-controller/api to v0.12.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-04-22 10:59:47 +03: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 1c33a2d45f Generate docs for v1alpha2
This switches the API doc generation from v1alpha1, to v1alpha2.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-13 11:01:45 +01:00
Michael Bridgen ebb2d6abea Use sourcev1.GitRepositoryRef
This changes the API so that the checkout field has a ref, the same as
GItRepository. This means you can check out a branch or a tag or a
particular commit. Most of these won't work unless you supply a branch
to push to as well.

An addtional change is that you can leave out the checkout altogether,
and the ref will default to that given in the GitRepository, or its
default. In the latter case, again you will need to provide a push
branch.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-13 11:01:42 +01:00
Michael Bridgen b28c5ccc04 Split author email and name into separate fields
This is a bit neater to read and write, and since I'm making breaking
changes anyway.

The name is now optional; an email is enough.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-04-13 10:50:01 +01: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
LWJ d1cfabf793 Fix nil pointer dereference and minor refactor
Signed-off-by: LWJ <lwjames1996@gmail.com>
2021-03-29 18:16:37 +01:00
LWJ b668e99a91 SigningKey modifications to align process with SOPS
Signed-off-by: LWJ <lwjames1996@gmail.com>
2021-03-24 21:54:31 +00:00
LWJ 4aa56f1013 Add SigningKey to CommitSpec
Signed-off-by: LWJ <lwjames1996@gmail.com>
2021-03-24 21:54:31 +00:00
Stefan Prodan 2e53745a03
Allow specifying the path for manifests updates
- Add optional `path` field to `spec.update`, defaults to the git repo root
- Restrict updates to the specified `spec.update.path`

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-16 11:58:21 +02:00
Stefan Prodan 4661519e64
Update dependencies
- sigs.k8s.io/kustomize/kyaml v0.10.15
- sigs.k8s.io/controller-runtime v0.8.2

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-12 12:07:27 +02:00
Michael Bridgen 97c7510d2e Add PushSpec to image update automation type
Signed-off-by: Michael Bridgen <michael@weave.works>
2021-03-04 17:35:58 +00:00
Stefan Prodan 4da2c82d23
Update dependencies
- sigs.k8s.io/controller-tools/cmd/controller-gen v0.4.1
- sigs.k8s.io/controller-runtime v0.8.2
- fluxcd/pkg/runtime v0.8.3
- fluxcd/source-controller v0.9.0

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-02-23 16:57:47 +02:00
Hidde Beydals 1d3978709e Update source-controller dependencies to v0.8.0
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-02-12 12:38: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
Michael Bridgen 6dfb1e84ee Default .strategy as well, to help migration
The `.spec.update` field has a default, which means you can leave it
out of new objects, and it will still be a valid spec. However,
existing objects will not be valid, because they will have a value for
`.spec.update` (so it won't get the default) which doesn't have a
value for `.strategy` (which is required, and an enum).

So: default the strategy field as well, so that existing objects are
still valid. This doesn't change the meaning of any existing objects,
since the outcome is the default, which is the only possible value
anyway.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-01-20 14:30:24 +00:00
Michael Bridgen bd76267be5 Reform update strategy types
It's convenient to be able to leave out the update strategy, since
there is only one possible value at present; and if there were
alternatives, the present choice would still be a reasonable
default. However, with the format as it is, this doesn't work with
OpenAPIv3 schema, so you have to supply a value, even though there are
no parameters:

```yaml
spec:
  update:
    setters: {}
```

A more self-explanatory format which _does_ work with defaulting is to
name the strategy rather than relying on the presence of a field:

```yaml
spec:
  update:
    strategy: Setters
```

The whole `update` field can be elided and left to default. This
doesn't preclude having other strategies later, even those with
parameters, e.g.,

```yaml
spec:
  update:
    strategy: Foo
    fooParam: 5
```

This commit changes the API types and code that uses them, and the CRD
manifest, and adds a test that checks the defaulting actually works.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-01-20 13:16:18 +00:00
Stefan Prodan db94176374
Update Kubernetes packages
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-01-18 14:54:42 +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 eb7ca1f3bd Record the last pushed SHA1 and the time it was pushed
This adds fields to the ImageUpdateAutomation status for recording the
commit last pushed; handy to see when you are expecting a change.

It also adapts the "steady state" message of the ready condition to
mention the last commit, in case that's where people are looking.

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-01-05 17:01:13 +00:00
Michael Bridgen 308748f515 Make the branch field mandatory
Instead of having an arbitrary default branch, make the checkout
branch mandatory. This needed a little finessing in the tests, since
they did not cover using different branches (though did cover using a
non-standard branch).

Signed-off-by: Michael Bridgen <michael@weave.works>
2021-01-05 11:33:52 +00:00
Michael Bridgen 5649927ef7 Bump GOTK packages
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-10 13:32:43 +00:00
Michael Bridgen 9a4fe520c6 Remove paths field from update.setters
The paths field in update.setters is to restrict the update to files
in particular paths.

But this is not implemented, and although it sounds useful, it's not
clear it's necessary. Until there's a known problem to be solved by
it, I'm removing it.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-09 11:10:54 +00:00
Michael Bridgen 5b4e93ebe4 Define const for ImageUpdateAutomation kind
This is handy for the CLI, among other places.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-07 14:59:25 +00:00
Michael Bridgen c069305a42 Change optional RunInterval to required Interval
This is to line up better with the other GitOps Toolkit API types.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-12-07 14:58:13 +00:00
Michael Bridgen a582871a79 Make sure reconcile request annotation works
The convention among GOTK controllers is to use a "reconcile request"
annotation to force a reconcilation, outside of spec or dependency
changes. This is used by e.g., the incoming webhooks handler. The
predicate `ChangePredicate`, already used by this controller, takes
this into account by allowing events that either caused the generation
to increment, _or_ changed the reconcile request annotation.

This commit adds a test that the automation will indeed run when the
annotation is set. This is a little delicate, because I have to rule
out _other_ reasons it might run. To do so, the test makes a change to
the git repo that will be overwritten by an automation run -- a commit
will not trigger a Reconcile call since it's entirely outside
Kubernetes.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-30 15:15:34 +00:00
Michael Bridgen 5cac345a43 Add Suspend field to spec
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-30 15:15:34 +00:00
Michael Bridgen 0cf879abd2 Add generated API docs
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-30 14:19:55 +00:00
Michael Bridgen a036d00db1 Add target for API docs generation to Makefile
This adapts the API docs generation, minimally, from
kustomize-controller to work here.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-30 14:17:03 +00:00
Michael Bridgen 38b7d2e8aa Document extra ready condition reasons
Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-26 12:17:09 +00:00
Michael Bridgen a09ac3f9d4 Make controller update ready condition
This gives ImageUpdateAutomation objects .status.conditions and
.status.observedGeneration fields, which are maintained by the
controller in the GOTK-standard way.

The only condition used is a Ready condition, compatible with kstatus
(and in common with other GOTK controllers). An object is marked Ready
if the reconciliation exits without an error, whether or not changes
were actually made. If the automation run cannot proceed, e.g.,
because the git repository referred to does not exist, or is not
cloneable, it will be marked as not ready.

This means the condition is a reliable guide to whether the particular
automation is operating or not; new objects will be marked ready as
soon as they have been run through successfully, and will stay ready
until there's a problem. Generally, if there _is_ a problem, the
object will be requeued with a backoff, or left to wait until
circumstances change (e.g., the object itself is edited); one way or
another, there will be a retry, and thereby an opportunity to
transition to ready.

Signed-off-by: Michael Bridgen <michael@weave.works>
2020-11-25 14:59:14 +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
Michael Bridgen da2f23caf1 Remove proof-of-concept update mode
The initial implementation of image updates required a single image
policy, and updated every image field that used the image, in the git
repo. This mode has limited practical value, and rather than
elaborating on it, it would be better to concentrate on making the
more carefully thought-through "setters" mode.
2020-10-22 14:53:41 +01:00
Michael Bridgen fd4b139dec Add setters strategy to ImageUpdateAutomation type
This is the means for telling the controller to use kyaml setters, per
the design in
https://github.com/fluxcd/toolkit/discussions/107#discussioncomment-82746
2020-09-28 11:06:18 +01:00
Michael Bridgen 48aac78343 Reassign copyright to Flux project 2020-08-10 17:48:24 +01:00
Michael Bridgen a1a204b613 Make comments match field names, in post 2020-08-05 19:49:31 +01:00
Michael Bridgen ccee0af7f0 Rename .ImagePolicy -> .ImagePolicyRef
.. to be in line with gitops-toolkit convention.
2020-08-05 19:09:52 +01:00
Michael Bridgen 140360f327 Move GitRepository -> Checkout.GitRepositoryRef
This moves the specificiation for the checkout of the git repo to a
struct `GitCheckoutSpec`; and, renames the field that's a reference to
a GitRepository so it has the suffix `Ref` per gitops-toolkit
convention.
2020-08-05 19:09:09 +01:00
Michael Bridgen 6dea89456b Use a specific git branch to sidestep assumptions
When I set my default branch for `git init` in ~/.gitconfig, tests
start failing. This is because go-git assumes a default of `master`
when e.g., pulling commits, but exec'ing git (as the test server does,
via gitkit) will get you a different branch.

The answer is to be explicit about the branch created in tests, and in
all operations like cloning. The natural end point is that the
automation object specifies a branch to use (or an empty value,
meaning let it default).
2020-08-03 13:34:14 +01:00
Michael Bridgen db373c5b22 Add runInterval and lastAutomationRunTime fields
The runInterval spec field gives a period for scheduled automation
runs, so it'll get done regularly whether or not the dependencies
appear to have changed.

The lastAutomationRunTime status field records the last time the
particular automation completed a run, whether or not it made
changes. This is informational, and will help with scheduling periodic
automations.
2020-08-02 21:29:25 +01:00
Hidde Beydals 8dc836e604 Change CRDs domain to 'image.toolkit.fluxcd.io'
This includes changes to the `README.md`, and a bump of the
`source-controller` dependency.
2020-07-31 17:05:56 +02:00
Michael Bridgen 71cf370dc8 Commit and push changes after running update
This makes the controller commit changes and push to the origin, when
it's run the update. There's some new fields in the
ImageUpdateAutomation type for specifying the commit message and
author.
2020-07-23 18:20:35 +01:00
Michael Bridgen 739f3c1770 Add update strategy that uses image policy
Just to get points on the board, this gives ImageUpdateAutomation an
`update` field into which you can plug the name of an ImagePolicy
resource (from the image reflector controller). The idea is that the
automation will then replace the image in the policy, anywhere it's
used, with its latest version.
2020-07-23 18:20:35 +01:00
Michael Bridgen 166ad7e3aa Refer to a git repository in ImageUpdateAutomation
This adds the field GitRepository in the ImageUpdateAutomation, for
referring to the git repository in which to make updates.
2020-07-23 18:14:28 +01:00
Michael Bridgen a048169819 Add ImageUpdateAutomation type and controller
kubebuilder create api --group image --version v1alpha1 \
      --kind ImageUpdateAutomation
2020-07-23 18:14:28 +01:00