Skip to content

Commit 9f1c136

Browse files
authored
Merge pull request #90 from fluxcd/api-examples
Add examples to the API spec docs
2 parents 4bde921 + fd47a1e commit 9f1c136

File tree

2 files changed

+110
-4
lines changed

2 files changed

+110
-4
lines changed

docs/spec/v1alpha1/imagepolicies.md

+76-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
The `ImagePolicy` type gives rules for selecting a "latest" image from a scanned
55
`ImageRepository`. This can be used to drive automation, as with the
6-
[image-automation-controller][]; or more generally, to inform other processes of the state of an
6+
[image-automation-controller][];
7+
or more generally, to inform other processes of the state of an
78
image repository.
89

910
## Specification
@@ -31,7 +32,6 @@ type ImagePolicySpec struct {
3132
The field `ImageRepositoryRef` names an `ImageRepository` object in the same namespace. It is this
3233
object that provides the scanned image metadata for the policy to use in selecting an image.
3334

34-
3535
### Policy
3636

3737
The ImagePolicy field specifies how to choose a latest image given the image metadata. The choice is
@@ -94,8 +94,8 @@ type TagFilter struct {
9494
The `FilterTags` field gives you the opportunity to filter the image tags _before_ they are
9595
considered by the policy rule.
9696

97-
The `Pattern` field takes a regular expression which can match anywhere in the tag string. Only tags
98-
that match the pattern are considered by the policy rule.
97+
The `Pattern` field takes a [regular expression][regex-go] which can match anywhere in the tag string.
98+
Only tags that match the pattern are considered by the policy rule.
9999

100100
The optional `Extract` value will be expanded for each tag that matches the pattern. The resulting
101101
values will be supplied to the policy rule instead of the original tags. If `Extract` is empty, then
@@ -124,5 +124,77 @@ The `LatestImage` field contains the image selected by the policy rule, when it
124124
There is one condition that may be present: the GitOps toolkit-standard `ReadyCondition`. This will
125125
be marked as true when the policy rule has selected an image.
126126

127+
## Examples
128+
129+
Select the latest `dev` branch build tagged as `<BRANCH>-<BUILD-ID>` (alphabetical):
130+
131+
```yaml
132+
kind: ImagePolicy
133+
spec:
134+
filterTags:
135+
pattern: '^dev-(?P<id>.*)'
136+
extract: '$id'
137+
policy:
138+
alphabetical:
139+
order: asc
140+
```
141+
142+
Select the latest stable version (semver):
143+
144+
```yaml
145+
kind: ImagePolicy
146+
spec:
147+
policy:
148+
semver:
149+
range: '>=1.0.0'
150+
```
151+
152+
Select the latest stable patch version in the 1.x range (semver):
153+
154+
```yaml
155+
kind: ImagePolicy
156+
spec:
157+
policy:
158+
semver:
159+
range: '>=1.0.0 <2.0.0'
160+
```
161+
162+
Select the latest version including pre-releases (semver):
163+
164+
```yaml
165+
kind: ImagePolicy
166+
spec:
167+
policy:
168+
semver:
169+
range: '>=1.0.0-0'
170+
```
171+
172+
Select the latest release candidate (semver):
173+
174+
```yaml
175+
kind: ImagePolicy
176+
spec:
177+
filterTags:
178+
pattern: '.*-rc.*'
179+
policy:
180+
semver:
181+
range: '^1.x-0'
182+
```
183+
184+
Select the latest release tagged as `RELEASE.<RFC3339-TIMESTAMP>`
185+
e.g. [Minio](https://hub.docker.com/r/minio/minio) (alphabetical):
186+
187+
```yaml
188+
kind: ImagePolicy
189+
spec:
190+
filterTags:
191+
pattern: '^RELEASE\.(?P<timestamp>.*)Z$'
192+
extract: '$timestamp'
193+
policy:
194+
alphabetical:
195+
order: asc
196+
```
197+
127198
[image-automation-controller]: https://github.com/image-automation-controller
128199
[semver-range]: https://github.com/Masterminds/semver#checking-version-constraints
200+
[regex-go]: https://golang.org/pkg/regexp/syntax

docs/spec/v1alpha1/imagerepositories.md

+34
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,39 @@ type ScanResult struct {
9898
There is one condition used: the GitOps toolkit-standard `ReadyCondition`. This will be marked as
9999
true when a scan succeeds, and false when a scan fails.
100100

101+
### Examples
102+
103+
Fetch metadata for a public image every ten minutes:
104+
105+
```yaml
106+
apiVersion: image.toolkit.fluxcd.io/v1alpha1
107+
kind: ImageRepository
108+
metadata:
109+
name: podinfo
110+
namespace: flux-system
111+
spec:
112+
interval: 10m
113+
image: ghcr.io/stefanprodan/podinfo
114+
```
115+
116+
Fetch metadata for a private image every minute:
117+
118+
```yaml
119+
apiVersion: image.toolkit.fluxcd.io/v1alpha1
120+
kind: ImageRepository
121+
metadata:
122+
name: podinfo
123+
namespace: flux-system
124+
spec:
125+
interval: 1m0s
126+
image: docker.io/org/image
127+
secretRef:
128+
name: regcred
129+
```
130+
131+
For private images, you can create a Kubernetes secret in the same namespace
132+
as the `ImageRepository` with `kubectl create secret docker-registry`,
133+
and reference it under `secretRef`.
134+
101135
[image-pull-secrets]: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
102136
[image-auto-provider-secrets]: https://toolkit.fluxcd.io/guides/image-update/#imagerepository-cloud-providers-authentication

0 commit comments

Comments
 (0)