Skip to content

Commit 255b651

Browse files
authored
Merge pull request #936 from adamwg/awg/imageconfig-rewrite
Document the ImageConfig path rewriting feature in Crossplane 1.20
2 parents 404bdec + ee31c7b commit 255b651

File tree

2 files changed

+310
-76
lines changed

2 files changed

+310
-76
lines changed

content/master/concepts/image-configs.md

Lines changed: 155 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 isn't taken into account for `ImageConfig` matching. That
29+
is, an `ImageConfig` matching the prefix `xpkg.crossplane.io/crossplane-contrib`
30+
doesn't match the following provider, even if 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,129 @@ 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+
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` replaces `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 useful when mirroring packages to a
235+
private registry, because it allows a package and all its dependencies to be
236+
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 still attempts to pull the dependency from
241+
`xpkg.crossplane.io`. With the preceding `ImageConfig`, the dependency is pulled
242+
from `registry1.com`.
243+
244+
Rewriting an image path with `ImageConfig` doesn't change the `spec.package`
245+
field of the package resource. The rewritten path is recorded in the
246+
`status.resolvedPackage` field. The preceding example 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 operations
260+
261+
{{<hint "tip" >}}
262+
Image rewriting is always done before other `ImageConfig` operations. If you
263+
wish to configure pull secrets or signature verification as well as rewriting,
264+
additional `ImageConfig` resources must match the rewritten image path.
265+
{{< /hint >}}
266+
267+
For example, if you are mirroring packages from `xpkg.crossplane.io` to
268+
`registry1.com` and need to configure pull secrets for `registry1.com`, two
269+
`ImageConfig` resources are necessary:
270+
271+
```yaml
272+
# Rewrite xpkg.crossplane.io -> registry1.com
273+
---
274+
apiVersion: pkg.crossplane.io/v1beta1
275+
kind: ImageConfig
276+
metadata:
277+
name: private-registry-rewrite
278+
spec:
279+
matchImages:
280+
- prefix: xpkg.crossplane.io
281+
rewriteImage:
282+
prefix: registry1.com
283+
284+
# Configure pull secrets for registry1.com
285+
---
286+
apiVersion: pkg.crossplane.io/v1beta1
287+
kind: ImageConfig
288+
metadata:
289+
name: private-registry-auth
290+
spec:
291+
matchImages:
292+
- type: Prefix
293+
prefix: registry1.com
294+
registry:
295+
authentication:
296+
pullSecretRef:
297+
name: private-registry-credentials
298+
```
299+
300+
## Debugging
301+
302+
When the package manager selects an `ImageConfig` for a package, it throws an
303+
event with the reason `ImageConfigSelection` and the name of the selected
304+
`ImageConfig` and injected pull secret. You can find these events both on the
305+
package and package revision resources. The package manager also updates the
306+
`appliedImageConfigRefs` field in the package status to show the purpose for
307+
which each `ImageConfig` was selected.
308+
309+
For example, the following event and status show that the `ImageConfig` named
310+
`acme-packages` was used to provide a pull secret for the configuration named
311+
`acme-configuration-foo`:
312+
313+
```shell
314+
kubectl describe configuration acme-configuration-foo
315+
...
316+
Status:
317+
Applied Image Config Refs:
318+
Name: acme-packages
319+
Reason: SetImagePullSecret
320+
...
321+
Events:
322+
Type Reason Age From Message
323+
---- ------ ---- ---- -------
324+
Normal ImageConfigSelection 45s packages/configuration.pkg.crossplane.io Selected pullSecret "acme-registry-credentials" from ImageConfig "acme-packages" for registry authentication
325+
```
326+
327+
If you can't find the expected event and `appliedImageConfigRefs` entry, ensure
328+
the prefix of the image reference matches the `matchImages` list of any
329+
`ImageConfig` resources in the cluster.
330+
331+
<!-- vale write-good.Passive = YES -->

0 commit comments

Comments
 (0)