Patch and Transforms
This document applies to Crossplane version v1.15 and not to the latest release v1.16.
Crossplane Compositions allow for “patch and transform” operations. With patches a Composition can apply changes to the resources defined by the Composition.
When users create Claims, Crossplane passes the settings in the Claim to the associated composite resource. Patches can use these settings to change the associated composite resource or managed resources.
Examples of using patch and transforms include:
- changing the name of the external resource
- mapping generic terms like “east” or “west” to specific provider locations
- appending custom labels or strings to resource fields
Crossplane expects patch and transform operations to be simple changes.
Use Composition Functions for more
complex or programmatic modifications.
A Composition patch is the action of changing a field.
A Composition transform modifies the values before
applying the patch.
Create a patch
Patches are part of an individual
inside a
.
The
field takes a
list of patches to apply to the individual resource.
Each patch has a
, which
defines what kind of patch action Crossplane applies.
Patches reference fields inside a composite resource or Composition differently
depending on the patch type, but all patches reference a
and
.
The
defines
the patch’s input values.
The
defines the
data to change with a patch.
Here is an example patch applied to a resource in a Composition.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3spec:
4 resources:
5 - name: my-composed-resource
6 base:
7 # Removed for brevity
8 patches:
9 - type: FromCompositeFieldPath
10 fromFieldPath: spec.field1
11 toFieldPath: metadata.labels["patchLabel"]
Selecting fields
Crossplane selects fields in a composite resource or managed resource with a subset of JSONPath selectors, called “field selectors.”
Field selectors can select any field in a composite resource or managed resource
object, including the metadata
, spec
or status
fields.
Field selectors can be a string matching a field name or an array index, in
brackets. Field names may use a .
character to select child elements.
Example field selectors
Here are some example selectors from a composite resource object.
Selector | Selected element |
---|---|
kind |
|
metadata.labels['crossplane.io/claim-name'] |
|
spec.desiredRegion |
|
spec.resourceRefs[0].name |
|
1$ kubectl get composite -o yaml
2apiVersion: example.org/v1alpha1
3kind: xExample
4metadata:
5 # Removed for brevity
6 labels:
7 crossplane.io/claim-name: my-example-claim
8 crossplane.io/claim-namespace: default
9 crossplane.io/composite: my-example-claim-978mh
10spec:
11 desiredRegion: eu-north-1
12 field1: field1-text
13 resourceRefs:
14 - apiVersion: s3.aws.upbound.io/v1beta1
15 kind: Bucket
16 name: my-example-claim-978mh-r6z64
17 - apiVersion: s3.aws.upbound.io/v1beta1
18 kind: Bucket
19 name: my-example-claim-978mh-cnlhj
20 - apiVersion: s3.aws.upbound.io/v1beta1
21 kind: Bucket
22 name: my-example-claim-978mh-rv5nm
23 # Removed for brevity
Reuse a patch
A Composition can reuse a patch object on multiple resources with a PatchSet.
To create a PatchSet, define a
object inside the
Composition’s
.
Each patch inside a PatchSet has a
and a list of
.
For multiple PatchSets only use a single
object.
Identify each unique PatchSet with a unique
.
Apply the PatchSet to a resource with a patch
.
Set the
to the
of the PatchSet.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4spec:
5 patchSets:
6 - name: my-patchset
7 patches:
8 - type: FromCompositeFieldPath
9 fromFieldPath: spec.desiredRegion
10 toFieldPath: spec.forProvider.region
11 resources:
12 - name: bucket1
13 base:
14 # Removed for brevity
15 patches:
16 - type: PatchSet
17 patchSetName: my-patchset
18 - name: bucket2
19 base:
20 # Removed for brevity
21 patches:
22 - type: PatchSet
23 patchSetName: my-patchset
A PatchSet can’t contain other PatchSets.
Crossplane ignores any transforms or policies in a PatchSet.
Patching between resources
Compositions can’t directly patch between resources in the same Composition.
For example, generating a network resource and patching the resource name to
a compute resource.
Status
field.A resource can patch to a user-defined
field in the composite resource.
A resource can then read from that
field to patch a field.
First, define a custom
in the Composite Resource Definition and a custom field, for example
1kind: CompositeResourceDefinition
2# Removed for brevity.
3spec:
4 # Removed for brevity.
5 versions:
6 - name: v1alpha1
7 schema:
8 openAPIV3Schema:
9 type: object
10 properties:
11 spec:
12 # Removed for brevity.
13 status:
14 type: object
15 properties:
16 secondResource:
17 type: string
Inside the Composition the resource with the source data uses a
patch to write data to the
field in the composite resource.
The destination resource uses a
patch to read data from the composite resource
field in the composite resource and write it to a label named
in the
managed resource.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 # Removed for brevity
9 patches:
10 - type: ToCompositeFieldPath
11 fromFieldPath: metadata.name
12 toFieldPath: status.secondResource
13 - name: bucket2
14 base:
15 apiVersion: s3.aws.upbound.io/v1beta1
16 kind: Bucket
17 # Removed for brevity
18 patches:
19 - type: FromCompositeFieldPath
20 fromFieldPath: status.secondResource
21 toFieldPath: metadata.labels['secondResource']
Describe the composite resource to view the
and the
value.
1$ kubectl describe composite
2Name: my-example-claim-jp7rx
3Spec:
4 # Removed for brevity
5 Resource Refs:
6 Name: my-example-claim-jp7rx-gfg4m
7 # Removed for brevity
8 Name: my-example-claim-jp7rx-fttpj
9Status:
10 # Removed for brevity
11 Second Resource: my-example-claim-jp7rx-gfg4m
Describe the destination managed resource to see the label
.
1$ kubectl describe bucket
2kubectl describe bucket my-example-claim-jp7rx-fttpj
3Name: my-example-claim-jp7rx-fttpj
4Labels: crossplane.io/composite=my-example-claim-jp7rx
5 secondResource=my-example-claim-jp7rx-gfg4m
Types of patches
Crossplane supports multiple patch types, each using a different source for data and applying the patch to a different location.
This section describes patches applied to individual resources inside a Composition.
For information about applying patches to an entire composite resource with a
Composition’s environment.patches
read the
Environment Configurations documentation.
Summary of Crossplane patches
Patch Type | Data Source | Data Destination |
---|---|---|
FromCompositeFieldPath | A field in the composite resource. | A field in the patched managed resource. |
ToCompositeFieldPath | A field in the patched managed resource. | A field in the composite resource. |
CombineFromComposite | Multiple fields in the composite resource. | A field in the patched managed resource. |
CombineToComposite | Multiple fields in the patched managed resource. | A field in the composite resource. |
FromEnvironmentFieldPath | Data in the in-memory EnvironmentConfig Environment | A field in the patched managed resource. |
ToEnvironmentFieldPath | A field in the patched managed resource. | The in-memory EnvironmentConfig Environment. |
CombineFromEnvironment | Multiple fields in the in-memory EnvironmentConfig Environment. | A field in the patched managed resource. |
CombineToEnvironment | Multiple fields in the patched managed resource. | A field in the in-memory EnvironmentConfig Environment. |
All the following examples use the same set of Compositions,
CompositeResourceDefinitions, Claims and EnvironmentConfigs.
Only the applied patches change between
examples.
All examples rely on Upbound provider-aws-s3 to create resources.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3metadata:
4 name: example-composition
5spec:
6 compositeTypeRef:
7 apiVersion: example.org/v1alpha1
8 kind: xExample
9 environment:
10 environmentConfigs:
11 - ref:
12 name: example-environment
13 resources:
14 - name: bucket1
15 base:
16 apiVersion: s3.aws.upbound.io/v1beta1
17 kind: Bucket
18 spec:
19 forProvider:
20 region: us-east-2
21 - name: bucket2
22 base:
23 apiVersion: s3.aws.upbound.io/v1beta1
24 kind: Bucket
25 spec:
26 forProvider:
27 region: us-east-2
1apiVersion: apiextensions.crossplane.io/v1
2kind: CompositeResourceDefinition
3metadata:
4 name: xexamples.example.org
5spec:
6 group: example.org
7 names:
8 kind: xExample
9 plural: xexamples
10 claimNames:
11 kind: ExampleClaim
12 plural: exampleclaims
13 versions:
14 - name: v1alpha1
15 served: true
16 referenceable: true
17 schema:
18 openAPIV3Schema:
19 type: object
20 properties:
21 spec:
22 type: object
23 properties:
24 field1:
25 type: string
26 field2:
27 type: string
28 field3:
29 type: string
30 desiredRegion:
31 type: string
32 boolField:
33 type: boolean
34 numberField:
35 type: integer
36 status:
37 type: object
38 properties:
39 url:
40 type: string
FromCompositeFieldPath
The
patch takes a value in a composite resource and applies it to a field in the
managed resource.
FromCompositeFieldPath
patch to apply options from users in their Claims to settings in managed
resource forProvider
settings.For example, to use the value
provided by
a user in a composite resource to a managed resource’s
.
The
value
is a field in the composite resource.
The
value is
the field in the managed resource to change.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: FromCompositeFieldPath
13 fromFieldPath: spec.desiredRegion
14 toFieldPath: spec.forProvider.region
View the managed resource to see the updated
1$ kubectl describe bucket
2Name: my-example-claim-qlr68-29nqf
3# Removed for brevity
4Spec:
5 For Provider:
6 Region: eu-north-1
ToCompositeFieldPath
The
writes
data from an individual managed resource to
the composite resource that created it.
ToCompositeFieldPath
patches to take data from one managed resource in a Composition and use it in a
second managed resource in the same Composition.For example, after Crossplane creates a new managed resource, take the value
and apply it
as a
in the composite
resource.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: ToCompositeFieldPath
13 fromFieldPath: status.atProvider.hostedZoneId
14 toFieldPath: metadata.labels['ZoneID']
View the created managed resource to see the
field.
1$ kubectl describe bucket
2Name: my-example-claim-p5pxf-5vnp8
3# Removed for brevity
4Status:
5 At Provider:
6 Hosted Zone Id: Z2O1EMRO9K5GLX
7 # Removed for brevity
Next view the composite resource and confirm the patch applied the
CombineFromComposite
The
patch takes values from the composite resource, combines them and applies them
to the managed resource.
CombineFromComposite
patch to create complex strings, like security policies and apply them to
a managed resource.For example, use the Claim value
and
to generate the
managed resource’s
The
patch only supports the
option.
The
are the
list of
values
from the composite resource to combine.
The only supported
is
.
Optionally you can apply a
, based on
Go string formatting to specify how to combine the
strings.
The
is the
field in the managed resource to apply the new string to.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: CombineFromComposite
13 combine:
14 variables:
15 - fromFieldPath: spec.desiredRegion
16 - fromFieldPath: spec.field2
17 strategy: string
18 string:
19 fmt: "my-resource-%s-%s"
20 toFieldPath: metadata.name
Describe the managed resource to see the applied patch.
CombineToComposite
The
patch takes values from the managed resource, combines them and applies them
to the composite resource.
CombineToComposite
patches to create a single field like a URL from multiple fields in a managed
resource.For example, use the managed resource
and
to generate a
custom
field.
The
patch only supports the
option.
The
are the
list of
the managed resource to combine.
The only supported
is
.
Optionally you can apply a
, based on
Go string formatting to specify how to combine the
strings.
The
is the
field in the composite resource to apply the new string to.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: CombineToComposite
13 combine:
14 variables:
15 - fromFieldPath: metadata.name
16 - fromFieldPath: spec.forProvider.region
17 strategy: string
18 string:
19 fmt: "https://%s.%s.com"
20 toFieldPath: status.url
View the composite resource to verify the applied patch.
1$ kubectl describe composite
2Name: my-example-claim-bjdjw
3API Version: example.org/v1alpha1
4Kind: xExample
5# Removed for brevity
6Status:
7 # Removed for brevity
8 URL: https://my-example-claim-bjdjw-r6ncd.us-east-2.com
FromEnvironmentFieldPath
EnvironmentConfigs are an alpha feature. They aren’t enabled by default.
For more information about using an EnvironmentConfig, read the EnvironmentConfigs documentation.
The
patch takes values from the in-memory EnvironmentConfig environment and applies
them to the managed resource.
FromEnvironmentFieldPath
to apply custom managed resource settings based on the current environment.For example, use the environment’s
value and
apply it as the
.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: FromEnvironmentFieldPath
13 fromFieldPath: locations.eu
14 toFieldPath: spec.forProvider.region
Verify managed resource to confirm the applied patch.
1kubectl describe bucket
2Name: my-example-claim-8vrvc-xx5sr
3Labels: crossplane.io/claim-name=my-example-claim
4# Removed for brevity
5Spec:
6 For Provider:
7 Region: eu-north-1
8 # Removed for brevity
ToEnvironmentFieldPath
EnvironmentConfigs are an alpha feature. They aren’t enabled by default.
For more information about using an EnvironmentConfig, read the EnvironmentConfigs documentation.
The
patch takes values the managed resource and applies them to the in-memory
EnvironmentConfig environment.
ToEnvironmentFieldPath
write data to the environment that any FromEnvironmentFieldPath
patch can access.For example, use the desired
value and
apply it as the environment’s
.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: ToEnvironmentFieldPath
13 fromFieldPath: spec.forProvider.region
14 toFieldPath: key1
Because the environment is in-memory, there is no command to confirm the patch wrote the value to the environment.
CombineFromEnvironment
EnvironmentConfigs are an alpha feature. They aren’t enabled by default.
For more information about using an EnvironmentConfig, read the EnvironmentConfigs documentation.
The
patch combines multiple values from the in-memory EnvironmentConfig environment and applies
them to the managed resource.
CombineFromEnvironment
patch to create complex strings, like security policies and apply them to
a managed resource.For example, combine multiple fields in the environment to create a unique
.
The
patch only supports the
option.
The only supported
is
.
The
are the
list of
values
from the in-memory environment to combine.
Optionally you can apply a
, based on
Go string formatting to specify how to combine the
strings.
The
is the
field in the managed resource to apply the new string to.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: CombineFromEnvironment
13 combine:
14 strategy: string
15 variables:
16 - fromFieldPath: key1
17 - fromFieldPath: key2
18 string:
19 fmt: "%s-%s"
20 toFieldPath: metadata.annotations[EnvironmentPatch]
Describe the managed resource to see new
.
1$ kubectl describe bucket
2Name: my-example-claim-zmxdg-grl6p
3# Removed for brevity
4Annotations: EnvironmentPatch: value1-value2
5# Removed for brevity
CombineToEnvironment
EnvironmentConfigs are an alpha feature. They aren’t enabled by default.
For more information about using an EnvironmentConfig, read the EnvironmentConfigs documentation.
The
patch combines multiple values from the managed resource and applies them to the in-memory EnvironmentConfig environment.
CombineToEnvironment
patch to create complex strings, like security policies to use in other managed resources.For example, combine multiple fields in the managed resource to create a unique
string and store it in the environment’s
value.
The string combines the
managed resource
and
.
The
patch only supports the
option.
The only supported
is
.
The
are the
list of
values in the managed resource to combine.
Optionally you can apply a
, based on
Go string formatting to specify how to combine the
strings.
The
is the
key in the environment to write the new string to.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: CombineToEnvironment
13 combine:
14 strategy: string
15 variables:
16 - fromFieldPath: kind
17 - fromFieldPath: spec.forProvider.region
18 string:
19 fmt: "%s.%s"
20 toFieldPath: key2
Because the environment is in-memory, there is no command to confirm the patch wrote the value to the environment.
Transform a patch
When applying a patch, Crossplane supports modifying the data before applying it as a patch. Crossplane calls this a “transform” operation.
Summary of Crossplane transforms.
Transform Type | Action |
---|---|
convert | Converts an input data type to a different type. Also called “casting.” |
map | Selects a specific output based on a specific input. |
match | Selects a specific output based on a string or regular expression. |
math | Applies a mathematical operation on the input. |
string | Change the input string using Go string formatting. |
Apply a transform directly to an individual patch with the
field.
A
requires a
, indicating the
transform action to take.
The other transform field is the same as the
, in this example,
.
The other fields depend on the patch type used.
This example uses a
transform, taking
the input
, matching
it to either
or
and returning the
corresponding AWS region for the
value.
1apiVersion: apiextensions.crossplane.io/v1
2kind: Composition
3# Removed for brevity
4 - name: bucket1
5 base:
6 apiVersion: s3.aws.upbound.io/v1beta1
7 kind: Bucket
8 spec:
9 forProvider:
10 region: us-east-2
11 patches:
12 - type: FromCompositeFieldPath
13 fromFieldPath: spec.desiredRegion
14 toFieldPath: spec.forProvider.region
15 transforms:
16 - type: map
17 map:
18 us: us-east-2
19 eu: eu-north-1
Convert transforms
The
transform type
changes the input data type to a different data type.
convert
type to
change any boolean or integer fields to strings.A
transform requires a
,
defining the output data type.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.numberField
4 toFieldPath: metadata.label["numberToString"]
5 transforms:
6 - type: convert
7 convert:
8 toType: string
Supported toType
values:
toType value | Description |
---|---|
bool | A boolean value of true or false . |
float64 | A 64-bit float value. |
int | A 32-bit integer value. |
int64 | A 64-bit integer value. |
string | A string value. |
object | An object. |
array | An array. |
Converting strings to booleans
When converting from a string to a bool
Crossplane considers the string values1
, t
, T
, TRUE
, True
and true
equal to the boolean value True
.
The strings0
, f
, F
, FALSE
, False
and false
are equal to the boolean value False
.
Converting numbers to booleans
Crossplane considers the integer 1
and float 1.0
equal to the boolean
value True
.
Any other integer or float value is False
.
Converting booleans to numbers
Crossplane converts the boolean value True
to the integer 1
or float64
1.0
.
The value False
converts to the integer 0
or float64 0.0
Converting strings to float64
When converting from a string
to a
Crossplane supports
an optional
field.
Using
translates
size suffixes like M
for megabyte or Mi
for megabit into the correct float64
value.
Add
to the
object to enable quantity
suffix support.
Converting strings to objects
Crossplane converts JSON strings to objects.
Add
to the
object which is
the only supported string format for this conversion.
The following example adds a tag to a resource with a
:
1 - type: FromCompositeFieldPath
2 fromFieldPath: spec.clusterName
3 toFieldPath: spec.forProvider.tags
4 transforms:
5 - type: string
6 string:
7 type: Format
8 fmt: '{"kubernetes.io/cluster/%s": "true"}'
9 - type: convert
10 convert:
11 toType: object
12 format: json
Converting strings to arrays
Crossplane converts JSON strings to arrays.
Add
to the
object which is
the only supported string format for this conversion.
Map transforms
The
transform type
maps an input value to an output value.
map
transform is useful for
translating generic region names like US
or EU
to provider specific region
names.The
transform compares the value
from the
to the
options listed in the
.
If Crossplane finds the value, Crossplane puts
the mapped value in the
.
is the string
then Crossplane uses
the string
for the
.
If
is the string
then Crossplane uses
the string
for the
.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: map
7 map:
8 "field1-text": "firstField"
9 "field2-text": "secondField"
In this example, the value of
is
.
1$ kubectl describe composite
2Name: my-example-claim-twx7n
3Spec:
4 # Removed for brevity
5 field1: field1-text
The annotation applied to the managed resource is
.
1$ kubectl describe bucket
2Name: my-example-claim-twx7n-ndb2f
3Annotations: crossplane.io/composition-resource-name: bucket1
4 myAnnotation: firstField
5# Removed for brevity.
Match transform
The
transform is like the
map
transform.
The
transform adds support for regular expressions along with exact
strings and can provide default values if there isn’t a match.
A
object requires a
object.
The
is a list of one or
more patterns to attempt to match the input value against.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: match
7 match:
8 patterns:
9 - type: literal
10 # Removed for brevity
11 - type: regexp
12 # Removed for brevity
Match
can be either
to match an
exact string or
to match a
regular expression.
Match an exact string
Use a
with
to match an
exact string.
On a successful match Crossplane provides the
to
the patch
.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: match
7 match:
8 patterns:
9 - type: literal
10 literal: "field1-text"
11 result: "matchedLiteral"
Match a regular expression
Use a
with
to match a regular
expression.
Define a
key with the value of the
regular expression to match.
On a successful match Crossplane provides the
to
the patch
.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: match
7 match:
8 patterns:
9 - type: regexp
10 regexp: '^field1.*'
11 result: "foundField1"
Using default values
Optionally you can provide a default value to use if there is no matching pattern.
The default value can either be the original input value or a defined default value.
Use
to
provide a default value if a match isn’t found.
For example if the string
isn’t
matched, Crossplane provides the
to the
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: match
7 match:
8 patterns:
9 - type: literal
10 literal: "UnknownString"
11 result: "foundField1"
12 fallbackTo: Value
13 fallbackValue: "StringNotFound"
To use the original input as the fallback value use
.
Crossplane uses the original
input for the
value.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["myAnnotation"]
5 transforms:
6 - type: match
7 match:
8 patterns:
9 - type: literal
10 literal: "UnknownString"
11 result: "foundField1"
12 fallbackTo: Input
Math transforms
Use the
transform to multiply
an input or apply a minimum or maximum value.
math
transform only supports
integer inputs.1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.numberField
4 toFieldPath: metadata.annotations["mathAnnotation"]
5 transforms:
6 - type: math
7 math:
8 ...
clampMin
The
uses a defined
minimum value if an input is larger than the
value.
For example, this
requires an
input to be greater than
.
If an input is lower than
, Crossplane uses the
value for the
.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.numberField
4 toFieldPath: metadata.annotations["mathAnnotation"]
5 transforms:
6 - type: math
7 math:
8 type: clampMin
9 clampMin: 20
clampMax
The
uses a defined
minimum value if an input is larger than the
value.
For example, this
requires an
input to be less than
.
If an input is higher than
, Crossplane uses the
value for the
.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.numberField
4 toFieldPath: metadata.annotations["mathAnnotation"]
5 transforms:
6 - type: math
7 math:
8 type: clampMax
9 clampMax: 5
Multiply
The
multiplies
the input by the
value.
For example, this
multiplies the
value from the
value by
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.numberField
4 toFieldPath: metadata.annotations["mathAnnotation"]
5 transforms:
6 - type: math
7 math:
8 type: multiply
9 multiply: 2
multiply
value only
supports integers.String transforms
The
transform applies
string formatting or manipulation to string inputs.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["stringAnnotation"]
5 transforms:
6 - type: string
7 string:
8 type: ...
String transforms support the following
String convert
The
converts the input based on one of the following conversion types:
ToUpper
- Change the string to all upper case letters.ToLower
- Change the string to all lower case letters.ToBase64
- Create a new base64 string from the input.FromBase64
- Create a new text string from a base64 input.ToJson
- Convert the input string to valid JSON.ToSha1
- Create a SHA-1 hash of the input string.ToSha256
- Create a SHA-256 hash of the input string.ToSha512
- Create a SHA-512 hash of the input string.ToAdler32
- Create an Adler32 hash of the input string.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["FIELD1-TEXT"]
5 transforms:
6 - type: string
7 string:
8 type: Convert
9 convert: "ToUpper"
String format
The
applies Go string formatting to the input.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.field1
4 toFieldPath: metadata.annotations["stringAnnotation"]
5 transforms:
6 - type: string
7 string:
8 type: Format
9 fmt: "the-field-%s"
Join
The
joins all
values in the input array into a string using the given separator.
This transform only works with array inputs.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.parameters.inputList
4 toFieldPath: spec.targetJoined
5 transforms:
6 - type: string
7 string:
8 type: Join
9 join:
10 separator: ","
Regular expression type
The
extracts
the part of the input matching a regular expression.
Optionally use a
to match a regular
expression capture group.
By default Crossplane matches the entire regular expression.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.desiredRegion
4 toFieldPath: metadata.annotations["euRegion"]
5 transforms:
6 - type: string
7 string:
8 type: Regexp
9 regexp:
10 match: '^eu-(.*)-'
11 group: 1
Trim prefix
The
uses
Go’s TrimPrefix and removes characters
from the beginning of a line.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.desiredRegion
4 toFieldPath: metadata.annotations["north-1"]
5 transforms:
6 - type: string
7 string:
8 type: TrimPrefix
9 trim: `eu-
Trim suffix
The
uses
Go’s TrimSuffix and removes characters
from the end of a line.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.desiredRegion
4 toFieldPath: metadata.annotations["eu"]
5 transforms:
6 - type: string
7 string:
8 type: TrimSuffix
9 trim: `-north-1'
Patch policies
Crossplane supports two types of patch policies:
fromFieldPath
mergeOptions
fromFieldPath policy
Using a fromFieldPath: Required
policy on a patch requires the
fromFieldPath
to exist in the composite resource.
fromFieldPath: Required
policy
may produce an error in the composite resource to help troubleshoot.By default, Crossplane applies the policy fromFieldPath: Optional
. With
fromFieldPath: Optional
Crossplane
ignores a patch if the fromFieldPath
doesn’t exist.
With
the composite resource produces an error if the
doesn’t exist.
1patches:
2 - type: FromCompositeFieldPath
3 fromFieldPath: spec.desiredRegion
4 toFieldPath: metadata.annotations["eu"]
5 policy:
6 fromFieldPath: Required
Merge options
By default when applying a patch the destination data is overridden. Use
to allow patches to
merge arrays and objects without overwriting them.
With an array input, use
to append the
array data to the end of the existing array.
With an object, use
to leave
existing object keys in tact. The patch updates any matching keys between the
input and destination data.