Skip to content

Commit c1ece7a

Browse files
committed
Document the ImageConfig path rewriting feature in Crossplane 1.20
While we're here, move the common content on matching and debugging to their own top-level headings, since they apply to all the different ImageConfig features. Signed-off-by: Adam Wolfe Gordon <[email protected]>
1 parent 404bdec commit c1ece7a

File tree

1 file changed

+154
-38
lines changed

1 file changed

+154
-38
lines changed

content/v1.20/concepts/image-configs.md

Lines changed: 154 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ description: "Image Configs is an API for centralized control of the configurati
1010
Crossplane package images. It allows you to configure package manager behavior
1111
for images globally, without needing to be referenced by other objects.
1212

13+
## Matching image references
14+
15+
`spec.matchImages` is a list of image references that the `ImageConfig` applies
16+
to. Each item in the list specifies the type and configuration of the image
17+
reference to match. The only supported type is `Prefix`, which matches the
18+
prefix of the image reference. No wildcards are supported. The `type` defaults
19+
to `Prefix` and can be omitted.
20+
21+
When there are multiple `ImageConfigs` matching an image reference, the one with
22+
the longest matching prefix is selected. If there are multiple `ImageConfigs`
23+
with the same longest matching prefix, one of them is selected
24+
arbitrarily. Please note that this situation occurs only if there are
25+
overlapping prefixes in the `matchImages` lists of different `ImageConfig`
26+
resources, which should be avoided.
27+
28+
The default registry is not taken into account for `ImageConfig` matching. That
29+
is, an `ImageConfig` matching the prefix `xpkg.crossplane.io/crossplane-contrib`
30+
will not be applied to the following provider, even when the default registry is
31+
`xpkg.crossplane.io`:
32+
33+
```yaml
34+
apiVersion: pkg.crossplane.io/v1
35+
kind: Provider
36+
metadata:
37+
name: provider-nop
38+
spec:
39+
package: crossplane-contrib/provider-nop:v0.4.0
40+
```
41+
1342
## Configuring a pull secret
1443
1544
You can use `ImageConfig` to inject a pull secret into the Crossplane package
@@ -46,43 +75,6 @@ following command:
4675
kubectl -n crossplane-system create secret docker-registry acme-registry-credentials --docker-server=registry1.com --docker-username=<user> --docker-password=<password>
4776
```
4877

49-
### Matching image references
50-
51-
`spec.matchImages` is a list of image references that the `ImageConfig` applies
52-
to. Each item in the list specifies the type and configuration of the image
53-
reference to match. The only supported type is `Prefix`, which matches the
54-
prefix of the image reference. No wildcards are supported. The `type` defaults
55-
to `Prefix` and can be omitted.
56-
57-
When there are multiple `ImageConfigs` matching an image reference, the one
58-
with the longest matching prefix is selected. If there are multiple
59-
`ImageConfigs` with the same longest matching prefix, one of them is selected
60-
arbitrarily. Please note that this situation occurs only if there are
61-
overlapping prefixes in the `matchImages` lists of different `ImageConfig`
62-
resources, which should be avoided.
63-
64-
### Debugging
65-
66-
When the package manager selects an `ImageConfig` for a package, it throws an
67-
event with the reason `ImageConfigSelection` and the name of the selected
68-
`ImageConfig` and injected pull secret. You can find these events both on the
69-
package and package revision resources.
70-
71-
For example, the following event indicates that the `ImageConfig` named
72-
`acme-packages` was selected for the configuration named `acme-configuration-foo`:
73-
74-
```shell
75-
$ kubectl describe configuration acme-configuration-foo
76-
...
77-
Events:
78-
Type Reason Age From Message
79-
---- ------ ---- ---- -------
80-
Normal ImageConfigSelection 45s packages/configuration.pkg.crossplane.io Selected pullSecret "acme-registry-credentials" from ImageConfig "acme-packages" for registry authentication
81-
```
82-
83-
If you can't find the expected event, ensure the prefix of the image reference
84-
matches the `matchImages` list of any `ImageConfig` resources in the cluster.
85-
8678
## Configuring signature verification
8779

8880
{{<hint "important" >}}
@@ -211,4 +203,128 @@ If you can't see this condition on the package revision resource, namely
211203
`ProviderRevision`, `ConfigurationRevision`, or `FunctionRevision`, ensure that
212204
the feature is enabled.
213205

214-
<!-- vale write-good.Passive = YES -->
206+
## Rewriting image paths
207+
208+
You can use an `ImageConfig` to pull package images from an alternative location
209+
such as a private registry. `spec.rewriteImages` specifies how to rewrite the
210+
paths of matched images.
211+
212+
Currently, only prefix replacement is supported. The prefix specified in
213+
`spec.rewriteImage.prefix` replaces the matched prefix from `matchImages`. For
214+
example, the following `ImageConfig` will replace `xpkg.crossplane.io` with
215+
`registry1.com` for any image with the prefix `xpkg.crossplane.io`.
216+
217+
```yaml
218+
apiVersion: pkg.crossplane.io/v1beta1
219+
kind: ImageConfig
220+
metadata:
221+
name: private-registry-rewrite
222+
spec:
223+
matchImages:
224+
- prefix: xpkg.crossplane.io
225+
rewriteImage:
226+
prefix: registry1.com
227+
```
228+
229+
In this example, installing the provider package
230+
`xpkg.crossplane.io/crossplane-contrib/provider-nop:v0.4.0` will result in the
231+
package manager pulling the provider from
232+
`registry1.com/crossplane-contrib/provider-nop:v0.4.0`.
233+
234+
Rewriting image paths via `ImageConfig` is particularly useful when mirroring
235+
packages to a private registry, since it allows a package and all its
236+
dependencies to be pulled from the same registry. For example, the provider
237+
`xpkg.crossplane.io/crossplane-contrib/provider-aws-s3` has a dependency on
238+
`xpkg.crossplane.io/crossplane-contrib/provider-family-aws`. If you mirror the
239+
packages to your own registry at `registry1.com` and install them without an
240+
`ImageConfig`, the package manager will still pull the dependency from
241+
`xpkg.crossplane.io`. With the `ImageConfig` shown above, the dependency will be
242+
pulled from `registry1.com`.
243+
244+
Rewriting an image path with `ImageConfig` does not change the `spec.package`
245+
field of the package resource. The rewritten path is recorded in the
246+
`status.resolvedPackage` field. The example above results in the following:
247+
248+
```shell
249+
kubectl describe provider crossplane-contrib-provider-family-aws
250+
...
251+
Spec:
252+
...
253+
Package: xpkg.crossplane.io/crossplane-contrib/provider-family-aws:v1.22.0
254+
Status:
255+
...
256+
Resolved Package: registry1.com/crossplane-contrib/provider-family-aws:v1.22.0
257+
```
258+
259+
### Interaction with other image configs
260+
261+
Image rewriting is always done before other `ImageConfig` operations. If you
262+
wish to configure pull secrets or signature verification for images being
263+
rewritten by an `ImageConfig`, the other configs must match the rewritten image
264+
path.
265+
266+
For example, if you are mirroring packages from `xpkg.crossplane.io` to
267+
`registry1.com` and need to configure pull secrets for `registry1.com`, two
268+
`ImageConfig` resources are necessary:
269+
270+
```yaml
271+
# Rewrite xpkg.crossplane.io -> registry1.com
272+
---
273+
apiVersion: pkg.crossplane.io/v1beta1
274+
kind: ImageConfig
275+
metadata:
276+
name: private-registry-rewrite
277+
spec:
278+
matchImages:
279+
- prefix: xpkg.crossplane.io
280+
rewriteImage:
281+
prefix: registry1.com
282+
283+
# Configure pull secrets for registry1.com
284+
---
285+
apiVersion: pkg.crossplane.io/v1beta1
286+
kind: ImageConfig
287+
metadata:
288+
name: private-registry-auth
289+
spec:
290+
matchImages:
291+
- type: Prefix
292+
prefix: registry1.com
293+
registry:
294+
authentication:
295+
pullSecretRef:
296+
name: private-registry-credentials
297+
```
298+
299+
## Debugging
300+
301+
When the package manager selects an `ImageConfig` for a package, it throws an
302+
event with the reason `ImageConfigSelection` and the name of the selected
303+
`ImageConfig` and injected pull secret. You can find these events both on the
304+
package and package revision resources. The package manager also updates the
305+
`appliedImageConfigRefs` field in the package status to indicate the purpose for
306+
which each `ImageConfig` was selected.
307+
308+
For example, the following event and status indicate that the `ImageConfig`
309+
named `acme-packages` was used to provide a pull secret for the configuration
310+
named `acme-configuration-foo`:
311+
312+
```shell
313+
kubectl describe configuration acme-configuration-foo
314+
...
315+
Status:
316+
Applied Image Config Refs:
317+
Name: acme-packages
318+
Reason: SetImagePullSecret
319+
...
320+
Events:
321+
Type Reason Age From Message
322+
---- ------ ---- ---- -------
323+
Normal ImageConfigSelection 45s packages/configuration.pkg.crossplane.io Selected pullSecret "acme-registry-credentials" from ImageConfig "acme-packages" for registry authentication
324+
```
325+
326+
If you can't find the expected event and `appliedImageConfigRefs` entry, ensure
327+
the prefix of the image reference matches the `matchImages` list of any
328+
`ImageConfig` resources in the cluster.
329+
330+
<!-- vale write-good.Passive = YES -->

0 commit comments

Comments
 (0)