From 7a7fc5210cc957ab46d8834979bab81fd7f73d63 Mon Sep 17 00:00:00 2001 From: 7navyasa <140163168+7navyasa@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:43:55 +1000 Subject: [PATCH] Adding DynamoDB table working composition and claim (#143) * dynamodb provisoned gsi lsi addition * lsi xrd correction * update dynamo definition and claim folder structure * Apply suggestions from code review removing region tablearn default namespace fields Co-authored-by: candonov <25967713+candonov@users.noreply.github.com> * updating config fields --------- Co-authored-by: candonov <25967713+candonov@users.noreply.github.com> --- .../dynamodb/definition.yaml | 141 ++++++++++++++++++ .../upbound-aws-provider/dynamodb/table.yaml | 89 +++++++++++ .../dynamodb/dynamodbtable-ondemand.yaml | 17 +++ ...namodbtable-provisioned-composite-gsi.yaml | 34 +++++ ...namodbtable-provisioned-composite-lsi.yaml | 31 ++++ .../dynamodbtable-provisioned-composite.yaml | 23 +++ .../dynamodb/dynamodbtable-provisioned.yaml | 20 +++ 7 files changed, 355 insertions(+) create mode 100644 compositions/upbound-aws-provider/dynamodb/definition.yaml create mode 100644 compositions/upbound-aws-provider/dynamodb/table.yaml create mode 100644 examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-ondemand.yaml create mode 100644 examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-gsi.yaml create mode 100644 examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-lsi.yaml create mode 100644 examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite.yaml create mode 100644 examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned.yaml diff --git a/compositions/upbound-aws-provider/dynamodb/definition.yaml b/compositions/upbound-aws-provider/dynamodb/definition.yaml new file mode 100644 index 00000000..5a915af1 --- /dev/null +++ b/compositions/upbound-aws-provider/dynamodb/definition.yaml @@ -0,0 +1,141 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apiextensions.crossplane.io/v1 +kind: CompositeResourceDefinition +metadata: + name: xdynamodbtables.awsblueprints.io +spec: + group: awsblueprints.io + names: + kind: XDynamoDBTable + plural: xdynamodbtables + claimNames: + kind: DynamoDBTable + plural: dynamodbtables + connectionSecretKeys: + - tableName + versions: + - name: v1alpha1 + served: true + referenceable: true + schema: + openAPIV3Schema: + type: object + description: Table is the Schema for the tables API + properties: + spec: + type: object + properties: + resourceConfig: + properties: + providerConfigName: + type: string + default: aws-provider-config + region: + type: string + tags: + additionalProperties: + type: string + description: Key-value map of resource tags. + type: object + type: object + dynamoConfig: + properties: + attribute: #required for hashKey and/or rangeKey + items: + properties: + name: #name of the hashKey and/or rangeKey + type: string + type: + enum: + - B #binary + - N #number + - S #string + type: string + required: + - name + - type + type: object + type: array + hashKey: + type: string + rangeKey: + type: string + billingMode: + type: string + default: PAY_PER_REQUEST + readCapacity: + type: number + writeCapacity: + type: number + name: + type: string + globalSecondaryIndex: + items: + properties: + hashKey: + type: string + name: + type: string + rangeKey: + type: string + readCapacity: + type: number + writeCapacity: + type: number + projectionType: + type: string + nonKeyAttributes: #required for gsi + items: + type: string + type: array + type: object + required: + - hashKey + - name + - rangeKey + - readCapacity + - writeCapacity + - projectionType + - nonKeyAttributes + type: array + localSecondaryIndex: + items: + properties: + name: + type: string + rangeKey: + type: string + projectionType: + type: string + nonKeyAttributes: #required for lsi + items: + type: string + type: array + type: object + required: + - name + - rangeKey + - projectionType + - nonKeyAttributes + type: array + required: + - hashKey + - attribute + type: object + required: + - resourceConfig + - dynamoConfig + status: + type: object + description: TableStatus defines the observed state of Table + properties: + tableArn: + description: Indicates this table's ARN + type: string + tableName: + description: Indicates this table's Name + type: string + required: + - spec diff --git a/compositions/upbound-aws-provider/dynamodb/table.yaml b/compositions/upbound-aws-provider/dynamodb/table.yaml new file mode 100644 index 00000000..b8eff8e5 --- /dev/null +++ b/compositions/upbound-aws-provider/dynamodb/table.yaml @@ -0,0 +1,89 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apiextensions.crossplane.io/v1 +kind: Composition +metadata: + name: table.dynamodb.awsblueprints.io + labels: + awsblueprints.io/provider: aws + awsblueprints.io/environment: dev +spec: + writeConnectionSecretsToNamespace: crossplane-system + compositeTypeRef: + apiVersion: awsblueprints.io/v1alpha1 + kind: XDynamoDBTable + patchSets: + - name: common-fields + patches: + - type: FromCompositeFieldPath + fromFieldPath: spec.resourceConfig.providerConfigName + toFieldPath: spec.providerConfigRef.name + - type: FromCompositeFieldPath + fromFieldPath: spec.resourceConfig.region + toFieldPath: spec.forProvider.region + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.name + toFieldPath: metadata.annotations[crossplane.io/external-name] + resources: + - name: table + connectionDetails: + - type: FromFieldPath + name: tableName + fromFieldPath: status.atProvider.id + base: + apiVersion: dynamodb.aws.upbound.io/v1beta1 + kind: Table + spec: + forProvider: + writeConnectionSecretToRef: + namespace: crossplane-system + patches: + - type: PatchSet + patchSetName: common-fields + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.attribute + toFieldPath: spec.forProvider.attribute + policy: + mergeOptions: + appendSlice: true + keepMapValues: true + - type: FromCompositeFieldPath + fromFieldPath: spec.resourceConfig.tags + toFieldPath: spec.forProvider.tags + policy: + mergeOptions: + keepMapValues: true + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.hashKey + toFieldPath: spec.forProvider.hashKey + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.billingMode + toFieldPath: spec.forProvider.billingMode + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.rangeKey + toFieldPath: spec.forProvider.rangeKey + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.readCapacity + toFieldPath: spec.forProvider.readCapacity + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.writeCapacity + toFieldPath: spec.forProvider.writeCapacity + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.globalSecondaryIndex + toFieldPath: spec.forProvider.globalSecondaryIndex + policy: + mergeOptions: + keepMapValues: true + - type: FromCompositeFieldPath + fromFieldPath: spec.dynamoConfig.localSecondaryIndex + toFieldPath: spec.forProvider.localSecondaryIndex + policy: + mergeOptions: + keepMapValues: true + - type: ToCompositeFieldPath + fromFieldPath: status.atProvider.id + toFieldPath: status.tableName + - type: ToCompositeFieldPath + fromFieldPath: status.atProvider.arn + toFieldPath: status.tableArn diff --git a/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-ondemand.yaml b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-ondemand.yaml new file mode 100644 index 00000000..92c2830b --- /dev/null +++ b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-ondemand.yaml @@ -0,0 +1,17 @@ +apiVersion: awsblueprints.io/v1alpha1 +kind: DynamoDBTable +metadata: + name: test-dynamodb-table-2 +spec: + writeConnectionSecretToRef: + name: dynamo3 + resourceConfig: + region: us-west-2 + tags: + namespace: team-x + cluster: crossplane + dynamoConfig: + attribute: + - name: UserId + type: S + hashKey: UserId \ No newline at end of file diff --git a/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-gsi.yaml b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-gsi.yaml new file mode 100644 index 00000000..1e4c19e9 --- /dev/null +++ b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-gsi.yaml @@ -0,0 +1,34 @@ +apiVersion: awsblueprints.io/v1alpha1 +kind: DynamoDBTable +metadata: + name: test-gsi-dynamodb-table +spec: + writeConnectionSecretToRef: + name: dynamogsi + resourceConfig: + region: us-west-2 + tags: + namespace: team-x + cluster: crossplane + dynamoConfig: + attribute: + - name: UserId + type: S + - name: UserName + type: S + - name: Pass + type: B + billingMode: PROVISIONED + globalSecondaryIndex: + - hashKey: UserName + name: UserNameIndex + nonKeyAttributes: + - UserId + projectionType: INCLUDE + rangeKey: Pass + readCapacity: 10 + writeCapacity: 10 + readCapacity: 20 + writeCapacity: 20 + hashKey: UserId + rangeKey: UserName diff --git a/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-lsi.yaml b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-lsi.yaml new file mode 100644 index 00000000..f250d135 --- /dev/null +++ b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite-lsi.yaml @@ -0,0 +1,31 @@ +apiVersion: awsblueprints.io/v1alpha1 +kind: DynamoDBTable +metadata: + name: test-lsi2-dynamodb-table +spec: + writeConnectionSecretToRef: + name: dynamolsi + resourceConfig: + region: us-west-2 + tags: + namespace: team-x + cluster: crossplane + dynamoConfig: + attribute: + - name: Artist + type: S + - name: SongTitle + type: S + - name: AlbumTitle + type: S + billingMode: PROVISIONED + localSecondaryIndex: + - name: AlbumTitleIndex + nonKeyAttributes: + - Genre + projectionType: INCLUDE + rangeKey: AlbumTitle + readCapacity: 20 + writeCapacity: 20 + hashKey: Artist + rangeKey: SongTitle diff --git a/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite.yaml b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite.yaml new file mode 100644 index 00000000..0a321d9d --- /dev/null +++ b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned-composite.yaml @@ -0,0 +1,23 @@ +apiVersion: awsblueprints.io/v1alpha1 +kind: DynamoDBTable +metadata: + name: test-pro-dynamodb-table +spec: + writeConnectionSecretToRef: + name: dynamopc + resourceConfig: + region: us-west-2 + tags: + namespace: team-x + cluster: crossplane + dynamoConfig: + attribute: + - name: UserId + type: S + - name: UserName + type: S + billingMode: PROVISIONED + readCapacity: 2 + writeCapacity: 2 + hashKey: UserId + rangeKey: UserName diff --git a/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned.yaml b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned.yaml new file mode 100644 index 00000000..d905749b --- /dev/null +++ b/examples/upbound-aws-provider/composite-resources/databases/dynamodb/dynamodbtable-provisioned.yaml @@ -0,0 +1,20 @@ +apiVersion: awsblueprints.io/v1alpha1 +kind: DynamoDBTable +metadata: + name: test-pro-dynamodb-table +spec: + writeConnectionSecretToRef: + name: dynamo + resourceConfig: + region: us-west-2 + tags: + namespace: team-x + cluster: crossplane + dynamoConfig: + attribute: + - name: UserId + type: S + billingMode: PROVISIONED + readCapacity: 2 + writeCapacity: 2 + hashKey: UserId