provider-upjet-aws: [Bug]: RDS Instance creation, resource already exists

Is there an existing issue for this?

  • I have searched the existing issues

Affected Resource(s)

No response

Resource MRs required to reproduce the bug

apiVersion: rds.aws.upbound.io/v1beta2
kind: Instance
metadata:
  annotations:
    crossplane.io/external-create-pending: "2024-06-06T17:43:44Z"
    crossplane.io/external-create-succeeded: "2024-06-06T17:43:44Z"
  creationTimestamp: "2024-06-06T15:55:19Z"
  finalizers:
  - finalizer.managedresource.crossplane.io
  generateName: ci-aseks6062802
  generation: 3
  labels:
    clusterId: ci-aseks6062802
  name: ci-aseks6062802qrvcs
  resourceVersion: "67343"
  uid: 48919564-24f7-43fb-b1ba-9dbbd8a9b1fa
spec:
  deletionPolicy: Delete
  forProvider:
    allocatedStorage: 256
    applyImmediately: true
    autoGeneratePassword: true
    backupRetentionPeriod: 3
    copyTagsToSnapshot: true
    dbSubnetGroupName: ci-aseks6062802k28ws
    dbSubnetGroupNameRef:
      name: ci-aseks6062802k28ws
    dbSubnetGroupNameSelector:
      matchLabels:
        clusterId: ci-aseks6062802
    engine: sqlserver-se
    engineVersion: 15.00.4236.7.v1
    identifier: ci-aseks6062802
    instanceClass: db.m5.xlarge
    licenseModel: license-included
    maxAllocatedStorage: 1000
    multiAz: false
    passwordSecretRef:
      key: password
      name: ci-aseks6062802
      namespace: sfd-ci-aseks6062802
    publiclyAccessible: true
    region: us-east-1
    skipFinalSnapshot: true
    storageEncrypted: true
    storageType: gp2
    username: testadmin
    vpcSecurityGroupIdRefs:
    - name: ci-aseks6062802-redis-mssql-sg2qb9w
    vpcSecurityGroupIdSelector:
      matchLabels:
        clusterId: ci-aseks6062802
        crossplane.io/forResource: redis-mssql
    vpcSecurityGroupIds:
    - sg-0ee65bd8753e2fdb8
  initProvider: {}
  managementPolicies:
  - '*'
  providerConfigRef:
    name: service-fabric
  writeConnectionSecretToRef:
    name: mssql-creds
    namespace: sfd-ci-aseks6062802

Steps to Reproduce

  • Created an RDS Instance on a kind cluster running crossplane.
  • It gets stuck sometimes with a resource already exists error, even though initially there was no such instance.

What happened?

  • A single RDS Instance should have been created.

Relevant Error Output Snippet

- lastTransitionTime: "2024-06-06T17:44:46Z"
    message: "async create failed: failed to create the resource: [{0 creating RDS
      DB Instance (ci-aseks6062802): DBInstanceAlreadyExists: DB instance already
      exists\n\tstatus code: 400, request id: 1be9b4f8-31de-42e5-89f5-99cdd8885597
      \ []}]"


### Crossplane Version

1.16.1

### Provider Version

1.2.0

### Kubernetes Version

1.29

### Kubernetes Distribution

Kind

### Additional Info

_No response_

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

I think we have enough evidence for this issue being fixed, therefore I’m closing it. Feel free to reopen, or preferably, to open a new one. Thank you everyone for your contribution πŸ™

@mergenci I can confirm the issue is now fixed with version v1.11.0. Although I had to recreate the claim. Thanks for fix!

@mergenci, we are currently using version v1.6.0 we are going to try the latest version, and I will report back if the upgrade resolves the issue

@karlderkaefer, thank you for your well-prepared report. Which provider version are you using?

The upstream Terraform fix that addresses the issue was consumed in https://github.com/crossplane-contrib/provider-upjet-aws/pull/1406, which was released in v1.10.0 β€” latest provider version is v1.11.0 by the way.

RDS creation errors are still possible in versions v1.10.0 or newer, simply because creation takes very long and something may timeout, like credentials do in your case. But such errors should be recovered from automatically in the next reconciliation loop, because now we receive the RDS ID (even if something timed out) with which we can successfully detect that the instance exists. In other words, we detect that the creation that we thought failed indeed succeeded.

In case your provider cannot detect that the instance was created successfully, and therefore is trying to recreate it and fail, it means there is another edge case we have yet to cover.

I faced same issue. It is producible but only for a specific instanceIdentifier. We tried other claims in same configuration, there were created just fine. I can share some details to these question

When it happens, does the database instance with the identifier set in your spec.forProvider actually exist in RDS? Is there any noticeable difference from the state in the managed resource? Does it have the crossplane-added tags?

Yes identifier exists on managed resource. The instance name in the aws console was the same. Yes crossplane tags are set on actual rds instance: crossplane-kind, crossplane-name, crossplane-providerconfig. We see following diff after the Session Token expired: allocated_storage:

  • allocated_storage: Old=β€œβ€, New=β€œ50”
  • apply_immediately: Old=β€œβ€, New=β€œtrue”
  • backup_retention_period: Old=β€œβ€, New=β€œ14”
  • backup_window: Old=β€œβ€, New=β€œ09:46-10:16”
  • db_name: Old=β€œβ€, New=β€œin***”
  • engine: Old=β€œβ€, New=β€œpostgres”
  • engine_version: Old=β€œβ€, New=β€œ16.2”
  • instance_class: Old=β€œβ€, New="db.t4g.large

How much time elapses between creating the Instance managed resource and getting the error? Some have stated that this is an intermittent issue. Roughly how often does it happen? Almost but not quite all the time? Rarely? Somewhere in between?

It’s reproducible and it takes 2min from initial successful create event to error state

Aug 21, 2024 @ 17:15:50.427	2024-08-21T15:15:49Z	DEBUG	provider-aws	Successfully requested creation of external resource	{"controller": "managed/rds.aws.upbound.io/v1beta2, kind=instance", "request": {"name":"redacted-db-rmhn9-pftjc"}, "uid": "596e470f-785c-4c73-ae10-2dbce233e424", "version": "54911722", "external-name": "", "external-name": ""}

Aug 21, 2024 @ 17:18:02.430	2024-08-21T15:18:01Z	DEBUG	provider-aws	Async create ended.	{"trackerUID": "596e470f-785c-4c73-ae10-2dbce233e424", "resourceName": "redacted-db-rmhn9-pftjc", "gvk": "rds.aws.upbound.io/v1beta2, Kind=Instance", "error": "async create failed: failed to create the resource: [{0 waiting for RDS DB Instance (redacted-db) create: ExpiredToken: The security token included in the request is expired\n\tstatus code: 403, request id: 42eeb4e2-13f3-4a75-92cf-63600cd87a35  []}]", "tfID": ""}

If you can run the provider-aws-rds pod with the --debug argument (using either a ControllerConfig or DeploymentRuntimeConfig), and can provide debug logs reproducing the issue, that would be very helpful.

tmp-logs.txt

Also here are cloudtrail request logs from first successful create event and first failing event tmp-success-redacted.json tmp-failing-reducted.json

Maybe worth to mention we set the identifier in our composition:

             - type: FromCompositeFieldPath
                fromFieldPath: metadata.labels[crossplane.io/claim-name]
                toFieldPath: spec.forProvider.identifier
             - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.instanceIdentifier
                toFieldPath: spec.forProvider.identifier

@mergenci Awesome stuff! Thank you very much for your work!