@@ -670,7 +670,7 @@ For example, after Crossplane creates a new managed resource, take the value
670670` hostedZoneID` and store it in the composite resource's status.
671671
672672{{< hint "important" >}}
673- To patch to composite resource status fields, you must first define the custom
673+ To patch to composite resource status fields, you must first define the custom
674674status fields in the CompositeResourceDefinition.
675675{{< /hint >}}
676676
@@ -1738,7 +1738,129 @@ patches:
17381738
17391739# # Composite resource connection details
17401740
1741- Function patch and Transform must define the specific secret keys a resource
1741+ Function Patch and Transform automatically aggregates connection details from
1742+ composed resources. Unlike other composition functions, Function Patch and
1743+ Transform can't access observed connection details to enable manually composing a
1744+ ` Secret` resource. Instead, it provides built-in automatic aggregation.
1745+
1746+ To expose connection details for a composite resource :
1747+
1748+ 1. Set `writeConnectionSecretToRef` on each composed resource that produces
1749+ connection details
1750+ 2. Define `connectionDetails` on each resource to specify which secret keys to
1751+ include in the aggregated secret
1752+ 3. Configure where to write the aggregated connection details secret (see
1753+ [options below](#setting-the-connection-secret-name-and-namespace))
1754+
1755+ The function automatically creates a `Secret` composed resource containing all
1756+ the aggregated connection details.
1757+
1758+ {{<hint "tip">}}
1759+ For a complete example of connection details aggregation with Function Patch and
1760+ Transform, see the [Connection Details Composition guide]({{<ref "connection-details-composition">}}).
1761+
1762+ If you need to transform connection details or manually compose a `Secret`
1763+ resource with more complex logic, use other functions like
1764+ ` function-go-templating` , `function-python`, or `function-kcl` instead. Those
1765+ functions have access to observed connection details, which Function Patch and
1766+ Transform doesn't provide.
1767+ {{</hint>}}
1768+
1769+ <!-- vale Google.Headings = NO -->
1770+ # ## v1 vs v2 behavior
1771+ <!-- vale Google.Headings = YES -->
1772+
1773+ This function handles composite resource connection details differently
1774+ depending on if the XR is Crossplane `v1` or `v2` style.
1775+
1776+ * `v1`: The function pipeline returns connection details and
1777+ Crossplane creates a separate connection secret for the XR/claim.
1778+ * `v2`: This function automatically composes a `Secret` containing the connection
1779+ details and includes it along with the XR's other composed resources.
1780+
1781+ # ## Setting the connection secret name and namespace
1782+
1783+ The function determines where to write the aggregated connection details secret
1784+ in this priority order :
1785+
1786+ # ### Function input
1787+
1788+ Configure the secret's name and namespace directly in the Composition's function
1789+ input using the `writeConnectionSecretToRef` field. This field supports both
1790+ static values and patches.
1791+
1792+ Use patches to read values from the XR :
1793+
1794+ ` ` ` yaml {label="input-patches"}
1795+ apiVersion: pt.fn.crossplane.io/v1beta1
1796+ kind: Resources
1797+ writeConnectionSecretToRef:
1798+ patches:
1799+ - type: FromCompositeFieldPath
1800+ fromFieldPath: spec.connection.name
1801+ toFieldPath: name
1802+ - type: FromCompositeFieldPath
1803+ fromFieldPath: spec.team
1804+ toFieldPath: namespace
1805+ resources:
1806+ # ... composed resources with connectionDetails
1807+ ` ` `
1808+
1809+ Or use static values :
1810+
1811+ ` ` ` yaml {label="input-static"}
1812+ apiVersion: pt.fn.crossplane.io/v1beta1
1813+ kind: Resources
1814+ writeConnectionSecretToRef:
1815+ name: fixed-secret-name
1816+ namespace: fixed-namespace
1817+ resources:
1818+ # ... composed resources with connectionDetails
1819+ ` ` `
1820+
1821+ This approach gives you full control and is useful for Cluster-scoped XRs where
1822+ you need to explicitly set the namespace, or when you want to transform the
1823+ secret name.
1824+
1825+ # ### Composite resource reference
1826+
1827+ If you don't configure `writeConnectionSecretToRef` in the function input, the
1828+ function reads the XR's `spec.writeConnectionSecretToRef` field if it exists in
1829+ the XR's schema :
1830+
1831+ ` ` ` yaml
1832+ apiVersion: example.org/v1alpha1
1833+ kind: UserAccessKey
1834+ metadata:
1835+ namespace: default
1836+ name: my-keys
1837+ spec:
1838+ writeConnectionSecretToRef:
1839+ name: my-keys-connection-details
1840+ ` ` `
1841+
1842+ You don't need to configure anything else in the Composition.
1843+
1844+ {{<hint "note">}}
1845+ The XRD must include `spec.writeConnectionSecretToRef` in its schema for users
1846+ to set this field.
1847+ {{</hint>}}
1848+
1849+ # ### Automatically generated
1850+
1851+ If the function can't determine the secret's name from the function input or XR
1852+ reference, it automatically generates a name based on the XR's name using the
1853+ format `<xr-name>-connection`.
1854+
1855+ For namespaced XRs, the function creates the secret in the same namespace as the XR.
1856+
1857+ For Cluster-scoped XRs, you must use either the function input or XR reference
1858+ approach to specify a namespace. Automatic generation doesn't work for Cluster-scoped
1859+ XRs because the function can't determine which namespace to use.
1860+
1861+ # ## Connection detail types
1862+
1863+ Function Patch and Transform must define the specific secret keys a composed resource
17421864creates with the `connectionDetails` object.
17431865
17441866{{<table "table table-sm" >}}
@@ -1830,13 +1952,12 @@ myStaticSecret: 18 bytes
18301952` ` `
18311953
18321954{{<hint "note" >}}
1833- The CompositeResourceDefinition can also limit which keys Crossplane stores from
1834- the composite resources.
1955+ The ` CompositeResourceDefinition` can also limit which keys Crossplane stores
1956+ for `v1` composite resources.
18351957
18361958By default an XRD writes all secret keys listed in the composed resources
18371959` connectionDetails` to the combined secret object.
18381960
1839-
18401961For more information on connection secrets read about
18411962[managed resources]({{<ref "../managed-resources/managed-resources">}}).
18421963{{</hint>}}
0 commit comments