crossplane: Functions can't modify XR `metadata` or `spec`
What happened?
I upgraded crossplane to 1.15 (from 1.14.x)
I transformed Composition to use patch-and-transform functions via crossplane beta convert pipeline-composition
In Composition I am trying to set an annotation on CompositeResource based on ManagedResource status
...
- fromFieldPath: status.atProvider.securityGroupID
toFieldPath: metadata.annotations[mysqlinstance.crossplane.sinch.com/sg]
type: ToCompositeFieldPath
ManagedResource and CompositeResource are healthy but annotation was not added
Before upgrading crossplane and changing composition to Pipeline mode (Patch And Transform) everything was working as expected, after above operations annotation is not added to CompositeResource anymore
Expected behaviour:
mysqlinstance.crossplane.sinch.com/sg annotation on CompositeResource should be added
How can we reproduce it?
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
creationTimestamp: "2024-02-21T14:33:56Z"
labels:
crossplane.io/xrd: xmysqlinstances.rds.aws.crossplane.sinch.com
name: mysqlinstances.rds.aws.crossplane.sinch.com-v1alpha1
spec:
compositeTypeRef:
apiVersion: rds.aws.crossplane.sinch.com/v1alpha1
kind: XMySQLInstance
publishConnectionDetailsWithStoreConfigRef:
name: default
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
environment: null
kind: Resources
patchSets: []
resources:
- base:
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: SecurityGroup
spec:
forProvider:
description: Security group for database
egress:
- fromPort: -1
ipProtocol: "-1"
ipRanges:
- cidrIp: 0.0.0.0/0
toPort: -1
ingress:
- fromPort: 3306
ipProtocol: tcp
toPort: 3306
userIdGroupPairs:
- description: Access from the k8s cluster
providerConfigRef:
name: crossplane-provider-aws
name: securitygroup
patches:
- fromFieldPath: metadata.annotations[core.crossplane.sinch.com/awsClusterSecurityGroup]
policy:
fromFieldPath: Required
toFieldPath: spec.forProvider.ingress[0].userIdGroupPairs[0].groupId
type: FromCompositeFieldPath
- fromFieldPath: metadata.annotations[core.crossplane.sinch.com/awsRegion]
policy:
fromFieldPath: Required
toFieldPath: spec.forProvider.region
type: FromCompositeFieldPath
- fromFieldPath: metadata.annotations[core.crossplane.sinch.com/awsVpcId]
policy:
fromFieldPath: Required
toFieldPath: spec.forProvider.vpcId
type: FromCompositeFieldPath
- fromFieldPath: status.atProvider.securityGroupID
toFieldPath: metadata.annotations[mysqlinstance.crossplane.sinch.com/sg]
type: ToCompositeFieldPath
What environment did it happen in?
Crossplane version:
crossplane: v1.15.0
aws-provider: crossplane-contrib/provider-aws:v0.46.0
kubernetes: 1.26.x
patch-and-transform function: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.0.0-20240222194345-0193c1d1fc74
Kubernetes distribution: local/kind
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (12 by maintainers)
I assume this is the major scenario especially since this is how the examples in the documentation are written.
I wonder if it’s not actually a problem though within function-patch-and-transform and it’s only a problem when the data is needed outside of the function? As long as the function executes the patches properly on every reconciliation, the internal copy of
observed.composite.resource.metadata.annotationswould be updated appropriately, making the data available to anyFromCompositeFieldPathpatches that reference it. The annotations would not be stored in the composite, but since they are reconstructed on every reconciliation it should still “work”. The one remaining downside is that it makes debugging harder because it’s not possible to examine the function-patch-and-transform stored state, the way it is in traditional P&T. So if the user is relying on the composite annotations being updated, it’s a reversion from traditional P&T, but it might not affect the results of the P&T sequences./fresh
@negz I think we still need to fix the underlying issue with being able to patch into
metadata.annotationsin a Composition Function. We do that all the time in our compositions, so moving them to functions is impossible without a complete rewrite unless we restore that functionality.I can understand not wanting to allow modifications to
spec, and possibly to othermetadataattributes, but we really needmetadata.annotationsto be available.I just tried latest patch-and-transform v4.0.0
FromEnvironmentFieldPath/ToEnvironmentFieldPathand now it is working!