upbound/platform-ref-aws

RDSInstance not created in a compositepostgresqlinstance but DBSubnetGroup is

prasek opened this issue · 3 comments

Follow the repro steps from #3

The composition created successfully, but only the dbsubnet group was added to resource refs:

Spec:
  Claim Ref:
    API Version:  aws.platformref.crossplane.io/v1alpha1
    Kind:         PostgreSQLInstance
    Name:         my-db
    Namespace:    default
  Composition Ref:
    Name:  compositepostgresqlinstances.aws.platformref.crossplane.io
  Parameters:
    Network Ref:
      Name:      network
    Storage GB:  20
  Resource Refs:
    API Version:  database.aws.crossplane.io/v1beta1
    Kind:         DBSubnetGroup
    Name:         my-db-6f5g6-hjxc5
    UID:          a9a73ab9-0b77-4cd7-96be-051c8eb825d5
  Write Connection Secret To Ref:
    Name:       abfe3e49-4599-4378-bcff-aa778c07292d
    Namespace:  crossplane-system
Events:
  Type    Reason             Age   From                                                             Message
  ----    ------             ----  ----                                                             -------
  Normal  SelectComposition  24m   defined/compositeresourcedefinition.apiextensions.crossplane.io  Successfully selected composition
k describe compositepostgresqlinstances.aws.platformref.crossplane.io
Name:         my-db-6f5g6
Namespace:
Labels:       crossplane.io/claim-name=my-db
              crossplane.io/claim-namespace=default
              crossplane.io/composite=my-db-6f5g6
Annotations:  <none>
API Version:  aws.platformref.crossplane.io/v1alpha1
Kind:         CompositePostgreSQLInstance
Metadata:
  Creation Timestamp:  2020-10-08T00:29:33Z
  Generate Name:       my-db-
  Generation:          4
  Managed Fields:
    API Version:  aws.platformref.crossplane.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
        f:generateName:
        f:labels:
          .:
          f:crossplane.io/claim-name:
          f:crossplane.io/claim-namespace:
          f:crossplane.io/composite:
      f:spec:
        .:
        f:claimRef:
          .:
          f:apiVersion:
          f:kind:
          f:name:
          f:namespace:
        f:compositionRef:
          .:
          f:name:
        f:parameters:
          .:
          f:networkRef:
            .:
            f:name:
          f:storageGB:
        f:resourceRefs:
        f:writeConnectionSecretToRef:
          .:
          f:name:
          f:namespace:
    Manager:         crossplane
    Operation:       Update
    Time:            2020-10-08T00:29:34Z
  Resource Version:  3128082
  Self Link:         /apis/aws.platformref.crossplane.io/v1alpha1/compositepostgresqlinstances/my-db-6f5g6
  UID:               abfe3e49-4599-4378-bcff-aa778c07292d
Spec:
  Claim Ref:
    API Version:  aws.platformref.crossplane.io/v1alpha1
    Kind:         PostgreSQLInstance
    Name:         my-db
    Namespace:    default
  Composition Ref:
    Name:  compositepostgresqlinstances.aws.platformref.crossplane.io
  Parameters:
    Network Ref:
      Name:      network
    Storage GB:  20
  Resource Refs:
    API Version:  database.aws.crossplane.io/v1beta1
    Kind:         DBSubnetGroup
    Name:         my-db-6f5g6-hjxc5
    UID:          a9a73ab9-0b77-4cd7-96be-051c8eb825d5
  Write Connection Secret To Ref:
    Name:       abfe3e49-4599-4378-bcff-aa778c07292d
    Namespace:  crossplane-system
Events:
  Type    Reason             Age   From                                                             Message
  ----    ------             ----  ----                                                             -------
  Normal  SelectComposition  24m   defined/compositeresourcedefinition.apiextensions.crossplane.io  Successfully selected composition

even through the RDSInstance is in the Composition:

k get composition compositepostgresqlinstances.aws.platformref.crossplane.io -o yaml
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: Composition
metadata:
  creationTimestamp: "2020-10-08T00:29:00Z"
  generation: 1
  labels:
    provider: aws
  managedFields:
  - apiVersion: apiextensions.crossplane.io/v1alpha1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:labels:
          .: {}
          f:provider: {}
        f:ownerReferences:
          .: {}
          k:{"uid":"afbc8666-6949-42c3-91d4-9ea879b32604"}:
            .: {}
            f:apiVersion: {}
            f:controller: {}
            f:kind: {}
            f:name: {}
            f:uid: {}
      f:spec:
        .: {}
        f:compositeTypeRef:
          .: {}
          f:apiVersion: {}
          f:kind: {}
        f:resources: {}
        f:writeConnectionSecretsToNamespace: {}
      f:status: {}
    manager: crossplane
    operation: Update
    time: "2020-10-08T00:29:15Z"
  name: compositepostgresqlinstances.aws.platformref.crossplane.io
  ownerReferences:
  - apiVersion: pkg.crossplane.io/v1alpha1
    controller: true
    kind: ConfigurationRevision
    name: platform-ref-aws-5b12f131139f
    uid: afbc8666-6949-42c3-91d4-9ea879b32604
  resourceVersion: "3127456"
  selfLink: /apis/apiextensions.crossplane.io/v1alpha1/compositions/compositepostgresqlinstances.aws.platformref.crossplane.io
  uid: 90c2f170-f49f-46bb-bc7f-24d3585abdae
spec:
  compositeTypeRef:
    apiVersion: aws.platformref.crossplane.io/v1alpha1
    kind: CompositePostgreSQLInstance
  resources:
  - base:
      apiVersion: database.aws.crossplane.io/v1beta1
      kind: DBSubnetGroup
      spec:
        forProvider:
          description: An excellent formation of subnetworks.
          region: us-west-2
        reclaimPolicy: Delete
    patches:
    - fromFieldPath: spec.parameters.networkRef.name
      toFieldPath: spec.forProvider.subnetIdSelector.matchLabels[networks.aws.platformref.crossplane.io/network-name]
  - base:
      apiVersion: database.aws.crossplane.io/v1beta1
      kind: RDSInstance
      spec:
        forProvider:
          dbInstanceClass: db.t2.small
          dbSubnetGroupNameSelector:
            matchControllerRef: true
          engine: postgres
          engineVersion: "9.6"
          masterUsername: masteruser
          publiclyAccessible: true
          region: us-west-2
          skipFinalSnapshotBeforeDeletion: true
        reclaimPolicy: Delete
        writeConnectionSecretToRef:
          namespace: crossplane-system
    connectionDetails:
    - fromConnectionSecretKey: username
    - fromConnectionSecretKey: password
    - fromConnectionSecretKey: endpoint
    - fromConnectionSecretKey: port
    patches:
    - fromFieldPath: metadata.uid
      toFieldPath: spec.writeConnectionSecretToRef.name
      transforms:
      - type: string
    - fromFieldPath: spec.parameters.storageGB
      toFieldPath: spec.forProvider.allocatedStorage
    - fromFieldPath: spec.parameters.networkRef.name
      toFieldPath: spec.forProvider.vpcSecurityGroupIDSelector.matchLabels[networks.aws.platformref.crossplane.io/network-name]
  writeConnectionSecretsToNamespace: crossplane-system

I was able to reproduce this behavior as well. At the same time, I also see the core crossplane pod in a crash loop:

NAME                                         READY   STATUS    RESTARTS   AGE
crossplane-86c5668889-fqx5q                  0/1     Error     4          11m

I believe it started crashing after I created the CompositePostgreSQLInstance, because before that I was able to create the CompositeNetwork and all of its managed resources just fine.

The crossplane pod logs show the following panic and stack trace (snippet of just the relavant crossplane portion of the stack):

E1008 03:32:08.384765       1 runtime.go:78] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 659 [running]:
...
	/usr/local/go/src/runtime/panic.go:969 +0x166
github.com/crossplane/crossplane/apis/apiextensions/v1alpha1.(*StringTransform).Resolve(0x0, 0x171b4c0, 0xc0013afeb0, 0xc001497090, 0xc000988ac0, 0x2, 0x2)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/apis/apiextensions/v1alpha1/composition_types.go:317 +0x42
github.com/crossplane/crossplane/apis/apiextensions/v1alpha1.(*Transform).Transform(0xc001497098, 0x171b4c0, 0xc0013afeb0, 0x0, 0x0, 0x0, 0x0)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/apis/apiextensions/v1alpha1/composition_types.go:241 +0x15c
github.com/crossplane/crossplane/apis/apiextensions/v1alpha1.(*Patch).Apply(0xc001497188, 0x7f8b625a24c0, 0xc00048a6d0, 0x7f8b62627458, 0xc00009aab8, 0x1, 0x19a2020)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/apis/apiextensions/v1alpha1/composition_types.go:172 +0x1ea
github.com/crossplane/crossplane/pkg/controller/apiextensions/composite/composed.(*DefaultOverlayApplicator).Overlay(0x2a60028, 0x1d8b1a0, 0xc00048a6d0, 0x1d85d00, 0xc00009aab8, 0xc0015f8540, 0x1af, 0x1af, 0x0, 0x0, ...)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/pkg/controller/apiextensions/composite/composed/api.go:107 +0x169
github.com/crossplane/crossplane/pkg/controller/apiextensions/composite/composed.(*Composer).Compose(0xc000822ba0, 0x1d547a0, 0xc000eff1a0, 0x1d8b1a0, 0xc00048a6d0, 0x1d85d00, 0xc00009aab8, 0xc0015f8540, 0x1af, 0x1af, ...)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/pkg/controller/apiextensions/composite/composed/composed.go:166 +0x145
github.com/crossplane/crossplane/pkg/controller/apiextensions/composite.(*Reconciler).Reconcile(0xc0001f3480, 0x0, 0x0, 0xc000dc39a0, 0xb, 0xc00139d800, 0x0, 0x0, 0x0)
	/Users/jared/dev/go/src/github.com/crossplane/crossplane/pkg/controller/apiextensions/composite/reconciler.go:274 +0x16b0

github.com/crossplane/crossplane/apis/apiextensions/v1alpha1.(*StringTransform).Resolve is hitting a nil ref, this could be triggered by the way our composition is authored (is it invalid?), but crossplane should handle that gracefully, that shouldn't cause a panic.

@jbw976 looks like I didn't look closely enough when I fixed this field in #1. The issue was that string: was indented, not that it shouldn't be there at all. Since it is removed, the type of transform is string, but the string transform struct is not present, which is where fmt gets required.

I can open a follow up to this first thing in the morning. I do agree that we shouldn't panic here either though of course, which would involve adding checks that the transform struct for the type is actually present. Apologies for the poor experience here 😕

good eye @hasheddan! I opened the upstream crossplane issue crossplane/crossplane#1815 to fix the crash.