Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit f79f484

Browse files
Adding DynamoDB Resource For Creation
**Why:** * allows you to create a dynamodb table via a CRD **This change addresses the need by:** * closes #6 Signed-off-by: Christopher Hein <[email protected]>
1 parent 3db23a4 commit f79f484

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

examples/dynamodb.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: operator.aws/v1alpha1
2+
kind: DynamoDB
3+
metadata:
4+
name: dynamodb-table
5+
spec:
6+
tableName: dynamodb-table
7+
hashAttribute:
8+
name: user_id
9+
type: S
10+
rangeAttribute:
11+
name: created_at
12+
type: S
13+
readCapacityUnits: 5
14+
writeCapacityUnits: 5

models/dynamodb.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
apiVersion: operator.aws/v1alpha1
2+
kind: ModelDefinition
3+
metadata:
4+
name: DynamoDBResource
5+
spec:
6+
kind: DynamoDB
7+
type: Spec # can be Spec or Data
8+
queue: true
9+
useCloudFormation: true
10+
resource:
11+
name: dynamodb
12+
plural: dynamodbs
13+
shortNames:
14+
- name: ddb
15+
- name: ddbs
16+
- name: dynamo
17+
- name: dynamotable
18+
- name: dynamotables
19+
body:
20+
schema:
21+
title: DynamoDB
22+
type: object
23+
properties:
24+
- key: tableName
25+
type: string
26+
description: |
27+
TableName is the name of the DynamoDB Table to be created.
28+
structKey: TableName
29+
templateKey: TableName
30+
- key: rangeAttribute
31+
type: object
32+
description: |
33+
RangeAttribute is the configuration for the range attribute.
34+
structKey: RangeAttribute
35+
templateKey: RangeAttribute
36+
properties:
37+
- key: Name
38+
type: string
39+
description: |
40+
Name is the name of the range attribute on the table.
41+
structKey: Name
42+
templateKey: RangeAttributeName
43+
- key: Type
44+
type: string
45+
description: |
46+
Type is the kind of range attribute that should be used.
47+
structKey: Type
48+
templateKey: RangeAttributeType
49+
- key: readCapacityUnits
50+
type: int
51+
description: |
52+
ReadCapacityUnits specifies the read capacity of the table.
53+
structKey: ReadCapacityUnits
54+
templateKey: ReadCapacityUnits
55+
- key: writeCapacityUnits
56+
type: int
57+
description: |
58+
WriteCapacityUnits specifies the write capacity of the table.
59+
structKey: WriteCapacityUnits
60+
templateKey: WriteCapacityUnits
61+
- key: hashAttribute
62+
type: object
63+
description: |
64+
HashAttribute is the configuration for the hash attribute on the table.
65+
structKey: HashAttribute
66+
templateKey: HashAttribute
67+
properties:
68+
- key: Name
69+
type: string
70+
description: |
71+
Name is the name of the hashing attribute on the table.
72+
structKey: Name
73+
templateKey: HashAttributeName
74+
- key: Type
75+
type: string
76+
description: |
77+
Type is the kind of hash attribute that should be used.
78+
structKey: Type
79+
templateKey: HashAttributeType
80+
output:
81+
schema:
82+
type: object
83+
properties:
84+
- key: tableName
85+
type: string
86+
description: |
87+
TableName is the output tablename incase it changed
88+
structKey: TableName
89+
templateKey: TableName
90+
- key: tableARN
91+
type: string
92+
description: |
93+
TableARN is the full Amazon ARN for the table created
94+
structKey: TableARN
95+
templateKey: TableArn

pkg/server/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
awsclient "github.com/christopherhein/aws-operator/pkg/client/clientset/versioned/typed/operator.aws/v1alpha1"
1111
"github.com/christopherhein/aws-operator/pkg/config"
1212
"github.com/christopherhein/aws-operator/pkg/operator/cloudformationtemplate"
13+
"github.com/christopherhein/aws-operator/pkg/operator/dynamodb"
1314
"github.com/christopherhein/aws-operator/pkg/operator/s3bucket"
1415
opkit "github.com/christopherhein/operator-kit"
1516
"k8s.io/api/core/v1"
@@ -44,6 +45,7 @@ func (c *Server) Run(stopChan chan struct{}) {
4445
resources := []opkit.CustomResource{
4546
cloudformationtemplate.Resource,
4647
s3bucket.Resource,
48+
dynamodb.Resource,
4749
}
4850
err = opkit.CreateCustomResources(*context, resources)
4951
if err != nil {
@@ -81,6 +83,9 @@ func (c *Server) Run(stopChan chan struct{}) {
8183

8284
s3controller := s3bucket.NewController(config, context, awsClientset)
8385
s3controller.StartWatch(v1.NamespaceAll, stopChan)
86+
87+
ddbcontroller := dynamodb.NewController(config, context, awsClientset)
88+
ddbcontroller.StartWatch(v1.NamespaceAll, stopChan)
8489
}
8590

8691
func getClientConfig(kubeconfig string) (*rest.Config, error) {

0 commit comments

Comments
 (0)