@@ -32,31 +32,34 @@ the GitRepository kind, and doesn't need the source-controller itself.
3232If you're not already using the [ GitOps toolkit] [ gotk ] , you can just
3333install the custom resource definition for GitRepository:
3434
35- kubectl apply -f https://raw.githubusercontent.com/fluxcd/source-controller/master /config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml
35+ kubectl apply -f https://raw.githubusercontent.com/fluxcd/source-controller/v0.0.18 /config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml
3636
3737** To install the image reflector controller**
3838
3939This controller relies on the image reflector controller. A working
4040configuration for the latter can be applied straight from the GitHub
41- repository (NB ` -k ` ) :
41+ repository:
4242
43- kubectl apply -k github.com/fluxcd/image-reflector-controller/config/default
43+ kustomize build github.com/fluxcd/image-reflector-controller// config/default/?ref=main | kubectl apply -f-
4444
4545### Installing the automation controller
4646
4747You can apply a working configuration directly from GitHub:
4848
49- kubectl apply -k github.com/fluxcd/image-automation-controller/config/default
49+ kustomize build github.com/fluxcd/image-automation-controller// config/default?ref=main | kubectl apply -f-
5050
5151or, in a clone of this repository,
5252
5353 make docker-build deploy
5454
55+ You will need to do the latter if you're trying the controller on a
56+ branch other than ` main ` .
57+
5558## How to use it
5659
5760Here is a quick example of configuring an automation. I'm going to use
58- [ cuttlefacts-app] [ cuttlefacts-app-repo ] because it's minimal and
59- thereby, easy to follow.
61+ [ cuttlefacts-app] [ cuttlefacts-app-repo ] because it's minimal and easy
62+ to follow.
6063
6164### Image policy
6265
@@ -92,7 +95,7 @@ kind: ImagePolicy
9295metadata:
9396 name: app-policy
9497spec:
95- imageRepository :
98+ imageRepositoryRef :
9699 name: app-image
97100 policy:
98101 semver:
@@ -111,7 +114,7 @@ NAME LATESTIMAGE
111114app-policy cuttlefacts/cuttlefacts-app:1.0.0
112115```
113116
114- ### Git repository and automation
117+ ### Creating the git repository object
115118
116119You need a writable git repository, so fork
117120[ ` cuttlefacts-app ` ] [ cuttlefacts-app-repo ] to your own account, and
176179$ $EDITOR repo.yaml
177180```
178181
179- Create the repository; be aware that unless you're running the full
180- GitOps toolkit suite, there will be no controller acting on it (and
181- doesn't need to be, for the purpose of this run-through).
182+ Create the repository object ; be aware that unless you're running the
183+ full GitOps toolkit suite, there will be no controller acting on it
184+ (and doesn't need to be, for the purpose of this run-through).
182185
183186``` bash
184187$ kubectl apply -f repo.yaml
@@ -188,9 +191,50 @@ NAME URL READY STATU
188191cuttlefacts-repo ssh://
[email protected] /squaremo/cuttlefacts-app 9s
189192```
190193
194+ ### Adding a marker to the YAML to update
195+
196+ To tell the controller what to update, you add some markers to the
197+ files to be updated. Each marker says which field to update, and which
198+ image policy to use for the new value.
199+
200+ In this case, it's the image in the deployment that needs to be
201+ updated, with the latest image from the image policy made
202+ earlier. Edit the file either locally or through GitHub, and add a
203+ marker to the file ` deploy/deployment.yaml ` at the line with the image
204+ field, ` image: cuttlefacts/cuttlefacts-app ` . The surrounding lines
205+ look like this:
206+
207+ ```
208+ containers:
209+ - name: server
210+ image: cuttlefacts/cuttlefacts-app
211+ imagePullPolicy: IfNotPresent
212+ ```
213+
214+ With the marker, they look like this:
215+
216+ ```
217+ containers:
218+ - name: server
219+ image: cuttlefacts/cuttlefacts-app # {"$imagepolicy": "default:app-policy"}
220+ imagePullPolicy: IfNotPresent
221+ ```
222+
223+ The marker is a comment at the end of the ` image: ` line, with a JSON
224+ value (so remember the double quotes), naming the image policy object
225+ to use for the value. A ` : ` character separates the namespace from the
226+ name of the ` ImagePolicy ` object. (The namespace is default because it
227+ wasn't specified in the manifest (` policy.yaml ` ) or when it was
228+ applied.)
229+
230+ Commit that change, and push it if you made the commit locally.
231+
232+ ### Creating the automation object
233+
191234Now we have an image policy, which calculates the most recent image,
192- and a git repository to update -- the last ingredient is to tie them
193- together with an ` ImageUpdateAutomation ` resource:
235+ and a git repository to update, and we've marked the field to update,
236+ in a file. The last ingredient is to tie these together with an
237+ ` ImageUpdateAutomation ` resource:
194238
195239```
196240$ cat > update.yaml <<EOF
@@ -199,19 +243,23 @@ kind: ImageUpdateAutomation
199243metadata:
200244 name: update-app
201245spec:
202- gitRepository:
203- name: cuttlefacts-repo
246+ checkout:
247+ gitRepositoryRef:
248+ name: cuttlefacts-repo
204249 update:
205- imagePolicy:
206- name: app-policy
250+ setters:
251+ paths:
252+ - .
207253 commit:
208254 authorName: UpdateBot
209255210256EOF
211257```
212258
213- Note that the image policy you created earlier, and the git
214- repository, are both mentioned.
259+ The git repository object is mentioned, and the ` setters ` value gives
260+ the paths to apply updates under.
261+
262+ Apply the file to create the automation object:
215263
216264 kubectl apply -f update.yaml
217265
@@ -226,4 +274,4 @@ repository][squaremo-auto-commit].
226274[ cuttlefacts-app-repo ] : https://github.com/cuttlefacts/cuttlefacts-app
227275[ github-fingerprints ] : https://docs.github.com/en/github/authenticating-to-github/githubs-ssh-key-fingerprints
228276[ cuttlefacts-app-deployment ] : https://github.com/cuttlefacts/cuttlefacts-app/blob/master/deploy/deployment.yaml
229- [ squaremo-auto-commit ] : https://github.com/squaremo/cuttlefacts-app-automated /commit/ad445a6cbd938be4b93116990954104f5730177e
277+ [ squaremo-auto-commit ] : https://github.com/squaremo/cuttlefacts-app-auto-setters /commit/edb6e7c0724bcc2226dc3077558f747e7adfb8e8
0 commit comments