### Example XR and Resources Manifest Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/example/multistep/README.md Defines an example XR, a S3 Bucket resource, and a S3 BucketACL resource, illustrating the desired state for the multistep pipeline. ```yaml --- apiVersion: example.crossplane.io/v1 kind: XR metadata: name: example-xr status: conditions: - lastTransitionTime: "2024-01-01T00:00:00Z" message: 'Unready resources: bucket, bucketACL' reason: Creating status: "False" type: Ready --- apiVersion: s3.aws.upbound.io/v1beta1 kind: Bucket metadata: annotations: crossplane.io/composition-resource-name: bucket generateName: example-xr- labels: crossplane.io/composite: example-xr ownerReferences: - apiVersion: example.crossplane.io/v1 blockOwnerDeletion: true controller: true kind: XR name: example-xr uid: "" spec: forProvider: region: eu-north-1 --- apiVersion: s3.aws.upbound.io/v1beta1 kind: BucketACL metadata: annotations: crossplane.io/composition-resource-name: bucketACL generateName: example-xr- labels: crossplane.io/composite: example-xr ownerReferences: - apiVersion: example.crossplane.io/v1 blockOwnerDeletion: true controller: true kind: XR name: example-xr uid: "" spec: forProvider: acl: private bucketSelector: matchControllerRef: true region: eu-north-1 ``` -------------------------------- ### Run Function with Default Settings Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Starts the function-patch-and-transform with all default settings. ```bash # Basic startup with default settings function-patch-and-transform ``` -------------------------------- ### Connection Detail Extraction Configuration Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/connection-details.md An example configuration for extracting connection details from a composed resource. It specifies how to retrieve username, password, endpoint, and port. ```yaml resources: - name: postgres-db base: apiVersion: rds.aws.upbound.io/v1beta1 kind: DBInstance connectionDetails: - name: username type: FromConnectionSecretKey fromConnectionSecretKey: username - name: password type: FromConnectionSecretKey fromConnectionSecretKey: password - name: endpoint type: FromFieldPath fromFieldPath: status.atProvider.endpoint - name: port type: FromValue value: "5432" ``` -------------------------------- ### Field Path Selection Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Demonstrates how to specify source and destination fields for a patch. ```yaml patches: - fromFieldPath: spec.location # Source field on composite resource toFieldPath: spec.forProvider.region # Destination field on composed resource ``` -------------------------------- ### Connection Secret Patching Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/connection-details.md An example demonstrating how to configure patches for `writeConnectionSecretToRef` using `FromCompositeFieldPath` and `CombineFromComposite` types to dynamically set the secret's name and namespace. ```yaml writeConnectionSecretToRef: patches: - type: FromCompositeFieldPath fromFieldPath: metadata.name toFieldPath: name - type: CombineFromComposite combine: variables: - fromFieldPath: metadata.namespace - fromFieldPath: metadata.name strategy: string string: fmt: "%s-creds" toFieldPath: namespace ``` -------------------------------- ### Multiple Readiness Checks (All Must Pass) Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Example demonstrating multiple readiness checks that must all pass for the resource to be considered ready. Includes condition, non-empty field, and string match checks. ```yaml resources: - name: postgres readinessChecks: - type: MatchCondition matchCondition: type: Ready status: "True" - type: NonEmpty fieldPath: status.atProvider.endpoint - type: MatchString fieldPath: status.state matchString: "available" ``` -------------------------------- ### Map Transform Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/transforms.md An example showing how to use the map transform to map a string input (e.g., location) to a specific output value (e.g., region). ```yaml patches: - type: FromCompositeFieldPath fromFieldPath: spec.location toFieldPath: spec.forProvider.region transforms: - type: map map: US: "us-east-1" EU: "eu-north-1" ASIA: "ap-southeast-1" ``` -------------------------------- ### Combine Configuration Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Combines multiple fields from the composite resource into a single output field using string formatting. ```yaml patches: - type: CombineFromComposite combine: variables: - fromFieldPath: metadata.name - fromFieldPath: spec.environment strategy: string string: fmt: "%s-%s-credentials" toFieldPath: metadata.generateName ``` -------------------------------- ### Math Transform Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/transforms.md An example demonstrating how to use the math transform to multiply a numeric field value. The default operation is Multiply. ```yaml patches: - type: FromCompositeFieldPath fromFieldPath: spec.cpuMillis toFieldPath: spec.cpu transforms: - type: math math: type: Multiply multiply: 1000 ``` -------------------------------- ### Example Patch with Match Transform Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/transforms.md Demonstrates a patch using a 'match' transform to map composite field paths to provider configurations based on literal values or regular expressions. ```yaml patches: - type: FromCompositeFieldPath fromFieldPath: spec.instanceSize toFieldPath: spec.forProvider.instanceType transforms: - type: match match: patterns: - type: literal literal: small result: '"t2.micro"' - type: literal literal: medium result: '"t2.small"' - type: regexp regexp: '^large.*' result: '"m5.xlarge"' fallbackValue: '"t2.micro"' ``` -------------------------------- ### Transform Pipeline Examples Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Shows sequential application of transforms to patch values. Includes map and string transforms. ```yaml transforms: - type: map map: US: us-east-1 EU: eu-north-1 - type: string string: type: Format fmt: "region-%s" ``` -------------------------------- ### Example Warning: Cannot Check Readiness Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This warning indicates a failure in the readiness check for a composed resource, but composition will continue. The resource will be marked as not ready. Fix the readiness check configuration or accept the initial not-ready state. ```go Warning: "cannot check readiness of composed resource 'my-service': readiness check at index 0 failed" ``` -------------------------------- ### Basic Ready Condition Check (Default) Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Example of a ComposedTemplate where no readinessChecks are explicitly defined, thus using the default check for the 'Ready' condition. ```yaml resources: - name: database base: apiVersion: rds.aws.upbound.io/v1beta1 kind: DBInstance # No readinessChecks specified - defaults to checking Ready condition ``` -------------------------------- ### Example Composition with Patch and Transform Function Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md This example demonstrates a Crossplane Composition that utilizes the patch-and-transform function. It defines a pipeline with a step to patch and transform resources, including common metadata, dynamic storage allocation based on composite fields, and connection details. ```yaml apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: name: aws-postgresql spec: compositeTypeRef: apiVersion: example.crossplane.io/v1 kind: PostgreSQLInstance mode: Pipeline pipeline: - step: patch-and-transform functionRef: name: function-patch-and-transform input: apiVersion: pt.fn.crossplane.io/v1beta1 kind: Resources patchSets: - name: common-metadata patches: - type: FromCompositeFieldPath fromFieldPath: metadata.labels toFieldPath: metadata.labels policy: toFieldPath: MergeObjects resources: - name: rds-instance base: apiVersion: rds.aws.upbound.io/v1beta1 kind: DBInstance spec: forProvider: engine: postgres engineVersion: "13" allocated Storage: 20 dbInstanceClass: db.t3.micro patches: - type: PatchSet patchSetName: common-metadata - type: FromCompositeFieldPath fromFieldPath: spec.size toFieldPath: spec.forProvider.allocatedStorage transforms: - type: map map: small: 20 medium: 100 large: 500 - type: FromCompositeFieldPath fromFieldPath: spec.region toFieldPath: spec.forProvider.region connectionDetails: - name: username type: FromConnectionSecretKey fromConnectionSecretKey: username - name: password type: FromConnectionSecretKey fromConnectionSecretKey: password - name: endpoint type: FromFieldPath fromFieldPath: status.atProvider.endpoint - name: port type: FromValue value: "5432" readinessChecks: - type: MatchCondition matchCondition: type: Ready status: "True" - type: NonEmpty fieldPath: status.atProvider.endpoint writeConnectionSecretToRef: namespace: default patches: - type: CombineFromComposite combine: variables: - fromFieldPath: metadata.name strategy: string string: fmt: "%s-postgres-credentials" toFieldPath: name ``` -------------------------------- ### Run Function with Combined Options Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Starts the function-patch-and-transform with a combination of debug logging, custom address, TLS certificates, and increased message size. ```bash # Combined options function-patch-and-transform \ --debug \ --address :9443 \ --tls-server-certs-dir /etc/ssl/function \ --max-recv-message-size 8 ``` -------------------------------- ### Example Error: Cannot Apply Environment Patch Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error occurs when a patch operation between the Composite Resource (XR) and the environment fails. Verify that the patch configuration correctly references valid field paths on both the XR and the environment. ```go Error: "cannot apply the 'FromCompositeFieldPath' environment patch at index 0: [details]" ``` -------------------------------- ### Use Function in Kubernetes Composition Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/README.md Example of how to integrate the patch-and-transform function into a Kubernetes Composition pipeline. ```yaml pipeline: - step: patch-and-transform functionRef: name: function-patch-and-transform input: apiVersion: pt.fn.crossplane.io/v1beta1 kind: Resources resources: # ... ``` -------------------------------- ### Composition Configuration for Patch-and-Transform Function Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/function.md Example of how to configure a Composition to use the patch-and-transform function in its pipeline. ```yaml apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: name: example spec: mode: Pipeline pipeline: - step: patch-and-transform functionRef: name: function-patch-and-transform input: apiVersion: pt.fn.crossplane.io/v1beta1 kind: Resources resources: - name: my-bucket base: apiVersion: s3.aws.upbound.io/v1beta1 kind: Bucket spec: forProvider: region: us-east-1 patches: - type: FromCompositeFieldPath fromFieldPath: spec.location toFieldPath: spec.forProvider.region transforms: - type: map map: EU: eu-north-1 US: us-east-1 ``` -------------------------------- ### Validation Error Example 2 Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/validation.md Example of a validation error for an unsupported value. ```yaml field: "resources.connectionDetails[1].type" reason: "Unsupported" message: "FromUnknown is not a supported connection detail type" ``` -------------------------------- ### Example Function Reference in Workflow Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This snippet shows how a previous function in a workflow might be referenced. Ensure that the referenced function produces the expected resource, in this case, a resource named 'my-resource'. ```yaml - step: previous-function functionRef: name: other-function # ... this must produce a resource named "my-resource" ``` -------------------------------- ### Example Warning: Cannot Extract Connection Details Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This warning signifies that connection detail extraction failed, but the processing will continue. Common causes include missing secret keys or invalid field paths. The resource will proceed without the specific connection detail. ```go Warning: "cannot extract composite resource connection details from composed resource 'my-db': field path 'status.invalid' not found" ``` -------------------------------- ### Validation Error Example 1 Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/validation.md Example of a validation error indicating a required field is missing. ```yaml field: "resources[0].patches[0].fromFieldPath" reason: "Required" message: "fromFieldPath must be set for patch type FromCompositeFieldPath" ``` -------------------------------- ### Example Error: Cannot Compose Connection Secret Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error indicates a failure in creating a v2 XR connection secret. It can stem from issues generating a valid secret reference or setting secret data. Ensure the `writeConnectionSecretToRef` configuration is correct and that patches reference valid XR fields. ```go Error: "cannot compose connection secret: cannot generate connection secret reference: [details]" ``` -------------------------------- ### Connection Secret Configuration Example Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Configures a connection secret for v2 XRs, including field path patches and combine transformations. ```yaml writeConnectionSecretToRef: name: app-connection-secret namespace: default patches: - type: FromCompositeFieldPath fromFieldPath: metadata.namespace toFieldPath: namespace - type: CombineFromComposite combine: variables: - fromFieldPath: metadata.name - fromFieldPath: spec.environment strategy: string string: fmt: "%s-%s-creds" toFieldPath: name ``` -------------------------------- ### Fatal Error: Cannot Get Observed Composed Resources Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error arises from an internal Crossplane function SDK problem during the retrieval of observed composed resources. Examine Crossplane logs for details. ```go Error: "cannot get Observed Composed Resources" ``` -------------------------------- ### Fatal Error: Cannot Get Desired Composed Resources Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error points to an internal Crossplane function SDK issue when fetching desired composed resources. Consult Crossplane logs for further insights. ```go Error: "cannot get Desired Composed Resources" ``` -------------------------------- ### Fatal Error: Cannot Get Desired Composite Resource Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error indicates an internal Crossplane function SDK issue when retrieving the desired XR. Review Crossplane logs for additional information. ```go Error: "cannot get Desired Composite Resource" ``` -------------------------------- ### Render Pipeline Resources Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/example/multistep/README.md Use the `make render` target to visualize the XR, composition, and functions configuration for the multistep pipeline. ```bash crossplane beta render xr.yaml composition.yaml functions.yaml -r ``` -------------------------------- ### Extend Function with Custom Interfaces Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/README.md Illustrates how to extend the function's capabilities by implementing custom interfaces for connection details extraction and readiness checking. ```go type ConnectionDetailsExtractor interface { ExtractConnection(cd xpresource.Composed, ...) (managed.ConnectionDetails, error) } type ReadinessChecker interface { IsReady(ctx context.Context, o ConditionedObject, ...) (bool, error) } ``` -------------------------------- ### Default Readiness Check Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Specifies the default readiness check, which verifies if the resource has a 'Ready' condition with a 'True' status. ```go ReadinessChecks: []ReadinessCheck{ { Type: ReadinessCheckTypeMatchCondition, MatchCondition: &MatchConditionReadinessCheck{ Type: "Ready", Status: "True", }, }, } ``` -------------------------------- ### Project File Structure Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/MANIFEST.md Overview of the generated documentation's file structure, including the purpose and line count for each file. ```text output/ ├── README.md (369 lines) - Project overview and architecture ├── INDEX.md (401 lines) - Navigation guide and quick reference ├── MANIFEST.md (this file) - Documentation manifest ├── configuration.md (577 lines) - CLI and function input configuration ├── types.md (745 lines) - Complete type definitions ├── errors.md (632 lines) - Error reference and solutions └── api-reference/ ├── function.md (100 lines) - Main composition function ├── patches.md (248 lines) - Patch application functions ├── transforms.md (455 lines) - Transform operations ├── connection-details.md (288 lines) - Connection secret handling ├── readiness-checks.md (342 lines) - Readiness determination └── validation.md (427 lines) - Input validation ``` -------------------------------- ### Import and Use Function in Go Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/README.md Demonstrates how to import and use the patch-and-transform function's types and structure within a Go application. ```go import "github.com/crossplane-contrib/function-patch-and-transform/input/v1beta1" func someFunction() { input := &v1beta1.Resources{} // ... populate input fn := &Function{log: logger} response, err := fn.RunFunction(ctx, request) } ``` -------------------------------- ### Fatal Error: Cannot Get Observed Composite Resource Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error signifies an internal Crossplane function SDK issue when retrieving the observed XR. Check Crossplane logs for more context. ```go Error: "cannot get Observed Composite Resource" ``` -------------------------------- ### Render Composed Resources Locally with Crossplane CLI Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md This shell command demonstrates how to use the Crossplane CLI to locally render composed resources defined by a composition, XR, and function configuration. This is useful for testing P&T logic without applying changes to a cluster. ```shell crossplane beta render xr.yaml composition.yaml functions.yaml ``` -------------------------------- ### Project Documentation Structure Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/INDEX.md This snippet shows the directory structure for the project's documentation, indicating the purpose of each file. ```text /output/ ├── README.md # Start here ├── INDEX.md # This file ├── configuration.md # CLI and YAML config ├── types.md # Type definitions ├── errors.md # Error reference └── api-reference/ ├── function.md # Main function ├── patches.md # Patch functions ├── transforms.md # Transform functions ├── connection-details.md # Connection functions ├── readiness-checks.md # Readiness functions └── validation.md # Validation functions ``` -------------------------------- ### Define Connection Detail Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Configures how to extract connection details from a composed resource. Specify the 'Name' for the secret key, 'Type' of source, and relevant source details like 'FromConnectionSecretKey', 'FromFieldPath', or a 'Value'. ```go type ConnectionDetail struct { Name string Type ConnectionDetailType FromConnectionSecretKey *string FromFieldPath *string Value *string } ``` -------------------------------- ### Fatal Error: Cannot Get Function Input Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error occurs when the function input cannot be parsed from the request. Ensure the 'input' field in the Composition pipeline step contains valid YAML with proper indentation. ```go Error: "cannot get Function input: [parsing error details]" ``` -------------------------------- ### StringCombine Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Defines the format string for combining multiple string values. Use Go's format string syntax with placeholders for the values to be combined. ```go type StringCombine struct { Format string } ``` -------------------------------- ### Dynamically Construct Secret Name using Patches Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md Utilize patches with `CombineFromComposite` to dynamically construct the connection secret name by combining XR fields. This example formats the name using a string pattern. ```yaml writeConnectionSecretToRef: patches: - type: CombineFromComposite toFieldPath: name combine: variables: - fromFieldPath: metadata.name - fromFieldPath: spec.parameters.environment strategy: string string: fmt: "%s-%s-credentials" ``` -------------------------------- ### Validation Error: Missing Required Field in Patch Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This validation error indicates that a required field for a specific patch type is missing. For example, `fromFieldPath` is necessary for `FromCompositeFieldPath` patches. Ensure the correct fields are specified based on the patch type. ```yaml Error field: resources[i].patches[j].fromFieldPath Message: "fromFieldPath must be set for patch type FromCompositeFieldPath" ``` -------------------------------- ### Run Function Tests Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md Execute `go test ./...` to run all unit and integration tests defined in the function's test files, such as `fn_test.go`. ```shell $ go test ./... ``` -------------------------------- ### Configure Writing Connection Secrets Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Configures where and how to write connection secrets for v2 XR resources. Specify the 'Name' and 'Namespace' for the secret, or use 'Patches' for dynamic construction. ```go type WriteConnectionSecretToRef struct { Name string Namespace string Patches []ConnectionSecretPatch } ``` -------------------------------- ### Build Crossplane Package Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md Build a Crossplane package (`.xpkg`) using `crossplane xpkg build`. This command embeds the runtime image and creates a deployable package for the function. ```shell $ crossplane xpkg build -f package --embed-runtime-image=runtime ``` -------------------------------- ### StringTransform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Provides configuration for various string manipulation operations, including formatting, conversion, trimming, regex matching, joining, and replacing. ```go type StringTransform struct { Type StringTransformType Format *string Convert *StringConversionType Trim *string Regexp *StringTransformRegexp Join *StringTransformJoin Replace *StringTransformReplace } ``` -------------------------------- ### IsReady Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Determines if a composed resource is ready based on configured readiness checks. It can operate with default behavior (checking the 'Ready' condition) or with custom readiness check configurations. ```APIDOC ## IsReady ### Description Determines if a composed resource is ready based on configured readiness checks. It can operate with default behavior (checking the 'Ready' condition) or with custom readiness check configurations. ### Signature ```go func IsReady(_ context.Context, o ConditionedObject, rc ...v1beta1.ReadinessCheck) (bool, error) ``` ### Parameters #### Context - **ctx** (`context.Context`) - Required - Context (currently unused but may be used for cancellation) #### Resource Object - **o** (`ConditionedObject`) - Required - The resource to check readiness for #### Readiness Checks - **rc** (`[]v1beta1.ReadinessCheck`) - Optional - Readiness check configurations ### Returns - **bool**: True if the resource is ready, false otherwise - **error**: Error if check validation or execution fails ### Behavior 1. If no readiness checks provided: - Returns true if the "Ready" condition has status "True" - This is the default behavior 2. If readiness checks provided: - All checks must pass for the resource to be considered ready - Returns false if any check fails - Stops on first error ``` -------------------------------- ### Composed Resource Template: Readiness Checks Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Defines checks to determine if a composed resource is ready. ```yaml readinessChecks: - type: MatchCondition matchCondition: type: Ready status: "True" - type: NonEmpty fieldPath: status.atProvider.endpoint ``` -------------------------------- ### String Transform: Format Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/transforms.md Applies a Go format string to the input, appending a suffix. Ensure the format string is correctly defined. ```yaml transforms: - type: string string: type: Format fmt: "%s-prod" ``` -------------------------------- ### IsReady Function Signature Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md The IsReady function checks resource readiness based on provided readiness checks. It returns true if the resource is ready, false otherwise, or an error if validation or execution fails. If no checks are provided, it defaults to checking the 'Ready' condition. ```go func IsReady(_ context.Context, o ConditionedObject, rc ...v1beta1.ReadinessCheck) (bool, error) ``` -------------------------------- ### Readiness Check Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md Valid readiness check types include None, NonEmpty, MatchString, MatchInteger, MatchTrue, MatchFalse, and MatchCondition. ```yaml resources: - name: my-resource readinessChecks: - type: MatchString fieldPath: status.ready matchString: "true" ``` -------------------------------- ### Build Function Runtime Image Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md Build the Docker image for the function's runtime environment using `docker build . --tag=runtime`. This image contains the compiled function. ```shell $ docker build . --tag=runtime ``` -------------------------------- ### Function Input: Environment Configuration (Alpha) Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Configures composition environment patches within the function's input. This feature is currently in Alpha. ```yaml environment: patches: - type: FromCompositeFieldPath fromFieldPath: spec.environment toFieldPath: environment.name ``` -------------------------------- ### Combine Transform Strategy Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md A 'strategy' must be provided for the 'combine' configuration. Currently, 'string' is the only supported strategy. ```yaml resources: - name: my-resource patches: - combine: strategy: string ``` -------------------------------- ### Resources Input Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Defines the top-level input structure for the patch-and-transform function. It includes patch sets, environment configuration, composed resource templates, and connection secret references. ```Go type Resources struct { TypeMeta metav1.TypeMeta ObjectMeta metav1.ObjectMeta PatchSets []PatchSet Environment *Environment Resources []ComposedTemplate WriteConnectionSecretToRef *WriteConnectionSecretToRef } ``` -------------------------------- ### Patch and Transform Execution Flow Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/README.md Details the step-by-step execution of the Patch and Transform function, from parsing input to returning the desired state. ```text RunFunction(request) → ├─ Parse & validate input ├─ Get observed/desired XR and composed resources ├─ Resolve PatchSets ├─ For each resource template: │ ├─ Render/get base template │ ├─ Apply all patches (XR → Resource, Resource → XR, Combines) │ ├─ Extract connection details from observed resource │ ├─ Check readiness │ └─ Add to desired composed resources ├─ Apply environment patches (if configured) ├─ Create connection Secret for v2 XRs (if needed) └─ Return desired state ``` -------------------------------- ### ReadinessCheckType Constants Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Defines the available types for readiness checks. These constants specify the kind of check to be performed on a resource's fields or conditions. ```go type ReadinessCheckType string const ( ReadinessCheckTypeNone ReadinessCheckType = "None" ReadinessCheckTypeNonEmpty ReadinessCheckType = "NonEmpty" ReadinessCheckTypeMatchString ReadinessCheckType = "MatchString" ReadinessCheckTypeMatchInteger ReadinessCheckType = "MatchInteger" ReadinessCheckTypeMatchTrue ReadinessCheckType = "MatchTrue" ReadinessCheckTypeMatchFalse ReadinessCheckType = "MatchFalse" ReadinessCheckTypeMatchCondition ReadinessCheckType = "MatchCondition" ) ``` -------------------------------- ### Full ReadinessCheck Struct Definition Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Defines the structure for configuring readiness checks, including various matching types and field paths. ```go type ReadinessCheck struct { Type ReadinessCheckType FieldPath *string MatchString *string MatchInteger *int64 MatchCondition *MatchConditionReadinessCheck } ``` -------------------------------- ### ComposedTemplate Structure Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Specifies the configuration for a single composed resource. It includes a name, base resource template, patches to apply, connection details to extract, and readiness checks. ```Go type ComposedTemplate struct { Name string Base *runtime.RawExtension Patches []ComposedPatch ConnectionDetails []ConnectionDetail ReadinessChecks []ReadinessCheck } ``` -------------------------------- ### Check Specific Condition Readiness Check Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Configures a readiness check to verify if the 'Available' condition has a status of 'True'. ```yaml resources: - name: deployment readinessChecks: - type: MatchCondition matchCondition: type: Available status: "True" ``` -------------------------------- ### Fatal Error: Missing Composed Resource (No Base) Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md This error happens when a resource template lacks a base and was not produced by a preceding function. Either add a 'base' template to the resource or ensure a previous function creates a resource with the same name. ```go Error: "composed resource 'my-resource' has no base template, and was not produced by a previous Function in the pipeline" ``` -------------------------------- ### MatchTransform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Enables pattern matching to select a result. It includes a list of patterns to match against and a fallback value or behavior if no pattern matches. ```go type MatchTransform struct { Patterns []MatchTransformPattern FallbackValue extv1.JSON FallbackTo MatchFallbackTo } ``` -------------------------------- ### MathTransform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Specifies a mathematical operation to be performed. Supported operations include Multiply, ClampMin, and ClampMax, each requiring specific parameters. ```go type MathTransform struct { Type MathTransformType Multiply *int64 ClampMin *int64 ClampMax *int64 } ``` -------------------------------- ### Handler: Cannot Render Patch Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md For 'Cannot render patch' errors, check that field paths exist and that transforms are correctly configured and produce the expected types. ```go // Check field paths exist and transforms are valid patches: - type: FromCompositeFieldPath fromFieldPath: spec.valid.field.path # Use correct field path toFieldPath: spec.dest.field transforms: # Ensure transforms produce the right type - type: map map: expectedKey: expectedValue ``` -------------------------------- ### Run Function on Custom Address Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Configures the function-patch-and-transform to listen on a custom address and port. ```bash # Custom address and port function-patch-and-transform --address :8443 ``` -------------------------------- ### Function Input: Resources Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Specifies the list of composed resource templates required for the function's input configuration. ```yaml resources: - name: my-bucket base: apiVersion: s3.aws.upbound.io/v1beta1 kind: Bucket spec: forProvider: region: us-east-1 ``` -------------------------------- ### Environment Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Defines the configuration for composition environment patches, an Alpha feature. It contains a list of environment-specific patches. ```Go type Environment struct { Patches []EnvironmentPatch } ``` -------------------------------- ### Generate Go Code for Function Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md Run `go generate ./...` to execute code generation tasks, typically for updating API types or other generated code within the function project. ```shell $ go generate ./... ``` -------------------------------- ### Readiness Check Field Path Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md A 'fieldPath' must be specified for readiness checks, except for 'None' and 'MatchCondition' types. ```yaml resources: - name: my-resource readinessChecks: - type: NonEmpty fieldPath: status.observedGeneration ``` -------------------------------- ### Run Function with TLS Certificates Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Specifies the directory for server TLS certificates and the CA for client verification when running the function. ```bash # Specify TLS certificates function-patch-and-transform \ --tls-server-certs-dir /etc/ssl/certs \ --address :9443 ``` -------------------------------- ### Composed Resource Template: Connection Details Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Specifies how to extract and propagate connection details from a composed resource to the XR. ```yaml connectionDetails: - name: username type: FromConnectionSecretKey fromConnectionSecretKey: username - name: endpoint type: FromFieldPath fromFieldPath: status.atProvider.endpoint - name: port type: FromValue value: "5432" ``` -------------------------------- ### Define Convert Transform Formats Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/types.md Specifies the input formats for type conversion operations. Options include 'none' (default), 'quantity' for Kubernetes Quantity, and 'json' for JSON strings. ```go type ConvertTransformFormat string const ( ConvertTransformFormatNone ConvertTransformFormat = "none" ConvertTransformFormatQuantity ConvertTransformFormat = "quantity" ConvertTransformFormatJSON ConvertTransformFormat = "json" ) ``` -------------------------------- ### Check Field Existence Readiness Check Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Configures a readiness check to verify if a specific field (status.loadBalancer.ingress) is non-empty. ```yaml resources: - name: service readinessChecks: - type: NonEmpty fieldPath: status.loadBalancer.ingress ``` -------------------------------- ### Validate ReadinessCheck Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/validation.md Validates a ReadinessCheck configuration. Ensures the type is valid and required fields are present based on the type. ```go func ValidateReadinessCheck(r v1beta1.ReadinessCheck) *field.Error ``` -------------------------------- ### Check Field Value Readiness Check Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Configures a readiness check to verify if the 'status.state' field matches the string 'running'. ```yaml resources: - name: instance readinessChecks: - type: MatchString fieldPath: status.state matchString: "running" ``` -------------------------------- ### Match Transform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Applies transformations based on matching patterns (literal or regex) and provides a fallback. ```yaml transforms: - type: match match: patterns: - type: literal literal: us-east result: "1" - type: regexp regexp: '^eu-.*' result: "2" fallbackValue: "0" fallbackTo: Value ``` -------------------------------- ### Handler: Cannot Parse Base Template Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md If you encounter 'Cannot parse base template', verify that your base configuration is valid YAML or JSON and has correct indentation. ```go // Verify your base is valid YAML/JSON resources: - name: my-resource base: apiVersion: example.com/v1beta1 kind: MyResource # Ensure valid YAML indentation ``` -------------------------------- ### RunReadinessCheck Function Signature Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md The RunReadinessCheck function executes a single readiness check against a resource. It validates the check configuration and returns true if the check passes, false otherwise, or an error if validation or execution fails. Missing field paths are treated as check failures. ```go func RunReadinessCheck(c v1beta1.ReadinessCheck, o ConditionedObject) (bool, error) ``` -------------------------------- ### RunReadinessCheck Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Executes a single readiness check against a resource. This function validates the check configuration and then performs the check based on its type. ```APIDOC ## RunReadinessCheck ### Description Executes a single readiness check against a resource. This function validates the check configuration and then performs the check based on its type. ### Signature ```go func RunReadinessCheck(c v1beta1.ReadinessCheck, o ConditionedObject) (bool, error) ``` ### Parameters #### Readiness Check Configuration - **c** (`v1beta1.ReadinessCheck`) - Required - The readiness check configuration #### Resource Object - **o** (`ConditionedObject`) - Required - The resource to check ### Returns - **bool**: True if the check passes, false otherwise - **error**: Error if validation or check execution fails ### Behavior 1. Validates the readiness check configuration 2. Executes the check based on its type 3. Returns silently (no error) for missing field paths (treats as check failure) ``` -------------------------------- ### Connection Detail Type-Specific Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md Provide the required field based on the connection detail type: 'fromConnectionSecretKey' for FromConnectionSecretKey, 'fromFieldPath' for FromFieldPath, and 'value' for FromValue. ```yaml resources: - name: my-resource connectionDetails: - type: FromFieldPath fromFieldPath: spec.claim.status.endpoint ``` ```yaml resources: - name: my-resource connectionDetails: - type: FromValue value: "my-static-value" ``` -------------------------------- ### Connection Detail Type Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md Specify the 'type' for connection details. Supported types are FromConnectionSecretKey, FromFieldPath, and FromValue. ```yaml resources: - name: my-resource connectionDetails: - type: FromConnectionSecretKey fromConnectionSecretKey: my-secret-key ``` -------------------------------- ### Check Boolean Field True Readiness Check Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Configures a readiness check to verify if the 'status.completed' field is true. ```yaml resources: - name: job readinessChecks: - type: MatchTrue fieldPath: status.completed ``` -------------------------------- ### Transform Pipeline Flow Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/README.md Illustrates the sequential application of transforms in the pipeline. Each transform processes the output of the previous one. ```text Input → [Transform 1] → [Transform 2] → ... → [Transform N] → Output ``` -------------------------------- ### Define Transform I/O Types Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/transforms.md Defines the possible input and output types for transformations. ```go type TransformIOType string const ( TransformIOTypeString TransformIOType = "string" TransformIOTypeBool TransformIOType = "bool" TransformIOTypeInt TransformIOType = "int" TransformIOTypeInt64 TransformIOType = "int64" TransformIOTypeFloat64 TransformIOType = "float64" TransformIOTypeObject TransformIOType = "object" TransformIOTypeArray TransformIOType = "array" ) ``` -------------------------------- ### Handler: Composed Resource Has No Base Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md If a composed resource has no base, you need to add one. This involves defining the 'base' field with the resource's API version and kind. ```go // Either add a base resources: - name: my-resource base: apiVersion: s3.aws.upbound.io/v1beta1 kind: Bucket ``` -------------------------------- ### supportsConnectionDetails Function Signature Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/connection-details.md Determines if an XR supports native v1 connection details or v2 style. It checks for the presence of the `spec.crossplane` field to differentiate. ```go func supportsConnectionDetails(xr *resource.Composite) bool ``` -------------------------------- ### Function Input: WriteConnectionSecretToRef Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Configures the location for writing connection secrets, applicable to v2 XRs only. ```yaml writeConnectionSecretToRef: name: my-app-connection namespace: default patches: - type: FromCompositeFieldPath fromFieldPath: metadata.namespace toFieldPath: namespace ``` -------------------------------- ### String Transform: Trim Prefix Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Removes a specified prefix from a string. ```yaml transforms: - type: string string: type: TrimPrefix trim: "prefix-" ``` -------------------------------- ### Run Function on Unix Socket Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Configures the function-patch-and-transform to listen on a Unix socket instead of TCP. ```bash # Listen on Unix socket function-patch-and-transform --network unix --address /tmp/function.sock ``` -------------------------------- ### Check Integer Field Readiness Check Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/readiness-checks.md Configures a readiness check to verify if the 'status.readyReplicas' field equals the integer 3. ```yaml resources: - name: replica-set readinessChecks: - type: MatchInteger fieldPath: status.readyReplicas matchInteger: 3 ``` -------------------------------- ### Output of Local Resource Rendering Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/README.md This YAML output shows the resources that would be composed by Crossplane based on the provided `xr.yaml`, `composition.yaml`, and `functions.yaml`. It illustrates the resulting XR and the composed S3 Bucket resource with its specified region. ```yaml --- apiVersion: example.crossplane.io/v1 kind: XR metadata: name: example-xr --- apiVersion: s3.aws.upbound.io/v1beta1 kind: Bucket metadata: annotations: crossplane.io/composition-resource-name: bucket generateName: example-xr- labels: crossplane.io/composite: example-xr ownerReferences: # Omitted for brevity spec: forProvider: region: us-east-2 ``` -------------------------------- ### String Transform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md When using the 'string' transform type, provide 'fmt' or 'convert' for string manipulation. ```yaml resources: - name: my-resource patches: - transforms: - type: string fmt: "%s-suffix" ``` -------------------------------- ### Apply Environment Patch Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/patches.md Applies patches between the composition environment and the composite resource. Used for integrating environment-specific configurations. ```go err := ApplyEnvironmentPatch(p, env, oxr, dxr) ``` -------------------------------- ### Validate Resources in RunFunction Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/validation.md Demonstrates calling ValidateResources early in the RunFunction to check for invalid input. Fatal validation errors will halt function execution. ```go input := &v1beta1.Resources{} if err := request.GetInput(req, input); err != nil { response.Fatal(rsp, errors.Wrap(err, "cannot get Function input")) return rsp, nil } if err := ValidateResources(input); err != nil { response.Fatal(rsp, errors.Wrap(err, "invalid Function input")) return rsp, nil } ``` -------------------------------- ### Function Input: PatchSets Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Defines named sets of reusable patches within the function's input configuration. ```yaml patchSets: - name: common-labels patches: - type: FromCompositeFieldPath fromFieldPath: metadata.labels toFieldPath: metadata.labels policy: toFieldPath: MergeObjects ``` -------------------------------- ### PatchInterface Methods Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/api-reference/patches.md Defines the interface that all patch types must implement, specifying methods to retrieve patch type, field paths, combine configurations, transforms, and policies. ```go type PatchInterface interface { GetType() v1beta1.PatchType GetFromFieldPath() string GetToFieldPath() string GetCombine() *v1beta1.Combine GetTransforms() []v1beta1.Transform GetPolicy() *v1beta1.PatchPolicy } ``` -------------------------------- ### Math Transform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md When using the 'math' transform type, ensure you provide the 'type' and the corresponding field (e.g., 'multiply', 'clampMin', 'clampMax'). ```yaml resources: - name: my-resource patches: - transforms: - type: math multiply: 10 ``` -------------------------------- ### Map Transform Configuration Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/configuration.md Maps input values to predefined output values. ```yaml transforms: - type: map map: small: "t2.micro" medium: "t2.small" large: "m5.xlarge" ``` -------------------------------- ### Readiness Check Match Value Source: https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/_autodocs/errors.md For the 'MatchString' readiness check type, the 'matchString' value cannot be nil. ```yaml resources: - name: my-resource readinessChecks: - type: MatchString fieldPath: status.phase matchString: "Succeeded" ```