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

Commit 655b5e5

Browse files
author
Christopher Hein
authored
Merge pull request #22 from christopherhein/feature/6-dynamo-resource
Add DynamoDB resource
2 parents 933f40f + f79f484 commit 655b5e5

File tree

17 files changed

+1268
-0
lines changed

17 files changed

+1268
-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
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
)
7+
8+
// +genclient
9+
// +genclient:noStatus
10+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
11+
12+
// DynamoDB defines the base resource
13+
type DynamoDB struct {
14+
metav1.TypeMeta `json:",inline"`
15+
metav1.ObjectMeta `json:"metadata"`
16+
Spec DynamoDBSpec `json:"spec"`
17+
Status DynamoDBStatus `json:"status"`
18+
Output DynamoDBOutput `json:"output"`
19+
AdditionalResources DynamoDBAdditionalResources `json:"additionalResources"`
20+
}
21+
// DynamoDBHashAttribute defines the HashAttribute resource for DynamoDB
22+
type DynamoDBHashAttribute struct {
23+
Name string `json:"Name"`
24+
Type string `json:"Type"`
25+
}
26+
27+
// DynamoDBRangeAttribute defines the RangeAttribute resource for DynamoDB
28+
type DynamoDBRangeAttribute struct {
29+
Name string `json:"Name"`
30+
Type string `json:"Type"`
31+
}
32+
33+
// DynamoDBSpec defines the Spec resource for DynamoDB
34+
type DynamoDBSpec struct {
35+
CloudFormationTemplateName string `json:"cloudFormationTemplateName"`
36+
CloudFormationTemplateNamespace string `json:"cloudFormationTemplateNamespace"`
37+
TableName string `json:"tableName"`
38+
RangeAttribute DynamoDBRangeAttribute `json:"rangeAttribute"`
39+
ReadCapacityUnits int `json:"readCapacityUnits"`
40+
WriteCapacityUnits int `json:"writeCapacityUnits"`
41+
HashAttribute DynamoDBHashAttribute `json:"hashAttribute"`
42+
}
43+
44+
45+
// DynamoDBOutput defines the output resource for DynamoDB
46+
type DynamoDBOutput struct {
47+
TableName string `json:"tableName"`
48+
TableARN string `json:"tableARN"`
49+
}
50+
51+
// DynamoDBStatus holds the status of the Cloudformation template
52+
type DynamoDBStatus struct {
53+
ResourceStatus string `json:"resourceStatus"`
54+
ResourceStatusReason string `json:"resourceStatusReason"`
55+
StackID string `json:"stackID"`
56+
}
57+
58+
// DynamoDBAdditionalResources holds the additional resources
59+
type DynamoDBAdditionalResources struct {
60+
}
61+
62+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
63+
64+
// DynamoDBList defines the list attribute for the DynamoDB type
65+
type DynamoDBList struct {
66+
metav1.TypeMeta `json:",inline"`
67+
metav1.ListMeta `json:"metadata"`
68+
Items []DynamoDB `json:"items"`
69+
}
70+
71+
func init() {
72+
localSchemeBuilder.Register(addDynamoDBTypes)
73+
}
74+
75+
func addDynamoDBTypes(scheme *runtime.Scheme) error {
76+
scheme.AddKnownTypes(SchemeGroupVersion,
77+
&DynamoDB{},
78+
&DynamoDBList{},
79+
)
80+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
81+
return nil
82+
}

pkg/apis/operator.aws/v1alpha1/zz_generated.deepcopy.go

Lines changed: 161 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)