Skip to content

Commit f746a11

Browse files
committed
Add guide to migrating to v1alpha2
This commit adds a step-by-step guide to rewriting specs for v1alpha2. Signed-off-by: Michael Bridgen <[email protected]>
1 parent b0fc415 commit f746a11

File tree

1 file changed

+182
-7
lines changed

1 file changed

+182
-7
lines changed

docs/spec/v1alpha2/imageupdateautomations.md

Lines changed: 182 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ the automation process checks the image policy named, and updates the field valu
99
image selected by the policy. The marker format is shown in the [image automation
1010
guide][image-auto-guide].
1111

12+
To see what has changed between the API version v1alpha1 and this version v1alpha2, read [the section on migration](#migrating-from-v1alpha1) at the bottom.
13+
1214
## Specification
1315

1416
```go
@@ -68,8 +70,8 @@ type SourceReference struct {
6870

6971
To be able to commit changes back, the referenced `GitRepository` object must refer to credentials
7072
with write access; e.g., if using a GitHub deploy key, "Allow write access" should be checked when
71-
creating it. Only the `url`, `secretRef` and `gitImplementation` (see just below) fields of the
72-
`GitRepository` are used.
73+
creating it. Only the `url`, `ref`, `secretRef` and `gitImplementation` (see just below) fields of
74+
the `GitRepository` are used.
7375

7476
The `gitImplementation` field in the referenced `GitRepository` object controls which git library is
7577
used. This will matter if you run on Azure, and possibly otherwise -- see [the source controller
@@ -192,11 +194,12 @@ want to put tokens in to control how CI reacts to commits made by automation. Fo
192194

193195
```yaml
194196
spec:
195-
commit:
196-
messageTemplate: |
197-
Automated image update by Flux
198-
199-
[ci skip]
197+
git:
198+
commit:
199+
messageTemplate: |
200+
Automated image update by Flux
201+
202+
[ci skip]
200203
```
201204

202205
The following section describes what data is available to use in the template.
@@ -417,6 +420,178 @@ There is one condition maintained by the controller, which is the usual `ReadyCo
417420
condition. This will be recorded as `True` when automation has run without errors, whether or not it
418421
resulted in a commit.
419422

423+
## Migrating from `v1alpha1`
424+
425+
For the most part, `v1alpha2` rearranges the API types to provide for future extension. Here are the
426+
differences, and where each `v1alpha1` field goes. A full example appears after the table.
427+
428+
### Moves and changes
429+
430+
| v1alpha1 field | change in v1alpha2 |
431+
+----------------+--------------------+
432+
| .spec.checkout | moved to `.spec.git.checkout`, and optional |
433+
| | `gitRepositoryRef` is now `.spec.sourceRef` |
434+
| | `branch` is now `ref`, and optional |
435+
| .spec.commit | moved to `.spec.git.commit` |
436+
| | `authorName` and `authorEmail` now `author.name` and `author.email` |
437+
| .spec.push | moved to `.spec.git.push` |
438+
439+
### Example of rewriting a v1alpha1 object to v1alpha2
440+
441+
This example shows the steps to rewrite a v1alpha1 ImageUpdateAutomation YAML to be a v1alpha2 YAML.
442+
443+
This is the v1alpha1 original:
444+
445+
```yaml
446+
apiVersion: image.toolkit.fluxcd.io/v1alpha1
447+
kind: ImageUpdateAutomation
448+
spec:
449+
checkout:
450+
gitRepositoryRef:
451+
name: auto-repo
452+
branch: main
453+
interval: 5m
454+
# omit suspend, which has not changed
455+
update:
456+
strategy: Setters
457+
path: ./app
458+
commit:
459+
authorName: fluxbot
460+
authorEmail: [email protected]
461+
messageTemplate: |
462+
An automated update from FluxBot
463+
[ci skip]
464+
signingKey:
465+
secretRef:
466+
name: git-pgp
467+
push:
468+
branch: auto
469+
```
470+
471+
**Change the API version**
472+
473+
The API version is now `image.toolkit.fluxcd.io/v1alpha2`:
474+
475+
```yaml
476+
apiVersion: image.toolkit.fluxcd.io/v1alpha1
477+
478+
# becomes
479+
480+
apiVersion: image.toolkit.fluxcd.io/v1alpha2
481+
```
482+
483+
**Move and adapt `.spec.checkout.gitRepositoryRef` to `.spec.sourceRef` and `.spec.git.checkout`**
484+
485+
The reference to a `GitRepository` object has moved to the field `sourceRef`. The `checkout` field
486+
moves under the `git` key, with the branch to checkout in a structure under `ref`.
487+
488+
```yaml
489+
spec:
490+
checkout:
491+
gitRepositoryRef:
492+
name: auto-repo
493+
branch:
494+
main
495+
496+
# becomes
497+
498+
spec:
499+
sourceRef:
500+
kind: GitRepository # the default, but good practice to be explicit here
501+
name: auto-repo
502+
git:
503+
checkout:
504+
ref:
505+
branch: main
506+
```
507+
508+
Note that `.spec.git.checkout` is now optional. If not supplied, the `.spec.ref` field from the
509+
`GitRepository` object is used as the checkout for updates.
510+
511+
**Move and adapt `.spec.commit` to `spec.git.commit`**
512+
513+
The `commit` field also moves under the `git` key, and the author is a structure rather than two
514+
fields.
515+
516+
```yaml
517+
spec:
518+
commit:
519+
authorName: fluxbot
520+
authorEmail: [email protected]
521+
messageTemplate: |
522+
An automated update from FluxBot
523+
[ci skip]
524+
signingKey:
525+
secretRef:
526+
name: git-pgp
527+
528+
# becomes
529+
530+
spec:
531+
git:
532+
commit:
533+
author:
534+
name: fluxbot
535+
536+
messageTemplate: |
537+
An automated update from FluxBot
538+
[ci skip]
539+
signingKey:
540+
secretRef:
541+
name: git-pgp
542+
```
543+
544+
**Move `.spec.push` to `.spec.git.push`**
545+
546+
The field `push` moves under the `git` key.
547+
548+
```yaml
549+
spec:
550+
push:
551+
branch: auto
552+
553+
# becomes
554+
555+
spec:
556+
git:
557+
push:
558+
branch: auto
559+
```
560+
561+
**Overall result**
562+
563+
The final YAML looks like this:
564+
565+
```yaml
566+
apiVersion: image.toolkit.fluxcd.io/v1alpha2
567+
kind: ImageUpdateAutomation
568+
spec:
569+
sourceRef: # moved from `.spec.checkout`
570+
kind: GitRepository
571+
name: auto-repo
572+
interval: 5m
573+
# omit suspend, which has not changed
574+
update:
575+
strategy: Setters
576+
path: ./app
577+
git:
578+
checkout: # moved under `git`, loses `gitRepositoryRef`
579+
ref:
580+
branch: main # moved into `ref` struct
581+
commit: # moved under `git`
582+
author:
583+
name: fluxbot # moved from `authorName`
584+
email: [email protected] # moved from `authorEmail`
585+
messageTemplate: |
586+
An automated update from FluxBot
587+
[ci skip]
588+
signingKey:
589+
secretRef:
590+
name: git-pgp
591+
push: # moved under `git`
592+
branch: auto
593+
```
594+
420595
[image-auto-guide]: https://toolkit.fluxcd.io/guides/image-update/#configure-image-update-for-custom-resources
421596
[git-repo-ref]: https://toolkit.fluxcd.io/components/source/gitrepositories/#specification
422597
[durations]: https://godoc.org/time#ParseDuration

0 commit comments

Comments
 (0)