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

Commit

Permalink
Merge pull request #22 from christopherhein/feature/6-dynamo-resource
Browse files Browse the repository at this point in the history
Add DynamoDB resource
  • Loading branch information
Christopher Hein committed Aug 2, 2018
2 parents 933f40f + f79f484 commit 655b5e5
Show file tree
Hide file tree
Showing 17 changed files with 1,268 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/dynamodb.yaml
@@ -0,0 +1,14 @@
apiVersion: operator.aws/v1alpha1
kind: DynamoDB
metadata:
name: dynamodb-table
spec:
tableName: dynamodb-table
hashAttribute:
name: user_id
type: S
rangeAttribute:
name: created_at
type: S
readCapacityUnits: 5
writeCapacityUnits: 5
95 changes: 95 additions & 0 deletions models/dynamodb.yaml
@@ -0,0 +1,95 @@
apiVersion: operator.aws/v1alpha1
kind: ModelDefinition
metadata:
name: DynamoDBResource
spec:
kind: DynamoDB
type: Spec # can be Spec or Data
queue: true
useCloudFormation: true
resource:
name: dynamodb
plural: dynamodbs
shortNames:
- name: ddb
- name: ddbs
- name: dynamo
- name: dynamotable
- name: dynamotables
body:
schema:
title: DynamoDB
type: object
properties:
- key: tableName
type: string
description: |
TableName is the name of the DynamoDB Table to be created.
structKey: TableName
templateKey: TableName
- key: rangeAttribute
type: object
description: |
RangeAttribute is the configuration for the range attribute.
structKey: RangeAttribute
templateKey: RangeAttribute
properties:
- key: Name
type: string
description: |
Name is the name of the range attribute on the table.
structKey: Name
templateKey: RangeAttributeName
- key: Type
type: string
description: |
Type is the kind of range attribute that should be used.
structKey: Type
templateKey: RangeAttributeType
- key: readCapacityUnits
type: int
description: |
ReadCapacityUnits specifies the read capacity of the table.
structKey: ReadCapacityUnits
templateKey: ReadCapacityUnits
- key: writeCapacityUnits
type: int
description: |
WriteCapacityUnits specifies the write capacity of the table.
structKey: WriteCapacityUnits
templateKey: WriteCapacityUnits
- key: hashAttribute
type: object
description: |
HashAttribute is the configuration for the hash attribute on the table.
structKey: HashAttribute
templateKey: HashAttribute
properties:
- key: Name
type: string
description: |
Name is the name of the hashing attribute on the table.
structKey: Name
templateKey: HashAttributeName
- key: Type
type: string
description: |
Type is the kind of hash attribute that should be used.
structKey: Type
templateKey: HashAttributeType
output:
schema:
type: object
properties:
- key: tableName
type: string
description: |
TableName is the output tablename incase it changed
structKey: TableName
templateKey: TableName
- key: tableARN
type: string
description: |
TableARN is the full Amazon ARN for the table created
structKey: TableARN
templateKey: TableArn
82 changes: 82 additions & 0 deletions pkg/apis/operator.aws/v1alpha1/dynamodb.go
@@ -0,0 +1,82 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DynamoDB defines the base resource
type DynamoDB struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec DynamoDBSpec `json:"spec"`
Status DynamoDBStatus `json:"status"`
Output DynamoDBOutput `json:"output"`
AdditionalResources DynamoDBAdditionalResources `json:"additionalResources"`
}
// DynamoDBHashAttribute defines the HashAttribute resource for DynamoDB
type DynamoDBHashAttribute struct {
Name string `json:"Name"`
Type string `json:"Type"`
}

// DynamoDBRangeAttribute defines the RangeAttribute resource for DynamoDB
type DynamoDBRangeAttribute struct {
Name string `json:"Name"`
Type string `json:"Type"`
}

// DynamoDBSpec defines the Spec resource for DynamoDB
type DynamoDBSpec struct {
CloudFormationTemplateName string `json:"cloudFormationTemplateName"`
CloudFormationTemplateNamespace string `json:"cloudFormationTemplateNamespace"`
TableName string `json:"tableName"`
RangeAttribute DynamoDBRangeAttribute `json:"rangeAttribute"`
ReadCapacityUnits int `json:"readCapacityUnits"`
WriteCapacityUnits int `json:"writeCapacityUnits"`
HashAttribute DynamoDBHashAttribute `json:"hashAttribute"`
}


// DynamoDBOutput defines the output resource for DynamoDB
type DynamoDBOutput struct {
TableName string `json:"tableName"`
TableARN string `json:"tableARN"`
}

// DynamoDBStatus holds the status of the Cloudformation template
type DynamoDBStatus struct {
ResourceStatus string `json:"resourceStatus"`
ResourceStatusReason string `json:"resourceStatusReason"`
StackID string `json:"stackID"`
}

// DynamoDBAdditionalResources holds the additional resources
type DynamoDBAdditionalResources struct {
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DynamoDBList defines the list attribute for the DynamoDB type
type DynamoDBList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []DynamoDB `json:"items"`
}

func init() {
localSchemeBuilder.Register(addDynamoDBTypes)
}

func addDynamoDBTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&DynamoDB{},
&DynamoDBList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
161 changes: 161 additions & 0 deletions pkg/apis/operator.aws/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 655b5e5

Please sign in to comment.