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

Commit

Permalink
adding elasticache non-gen code
Browse files Browse the repository at this point in the history
  • Loading branch information
sepulworld committed Dec 27, 2018
1 parent 9fcf5ca commit 31dd9f0
Show file tree
Hide file tree
Showing 12 changed files with 535 additions and 5 deletions.
160 changes: 160 additions & 0 deletions cloudformation/elasticache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
AWSTemplateFormatVersion: "2010-09-09"
Description: 'AWS Operator - Amazon Elasticache Cluster'
Parameters:
Namespace:
Description: >-
This is the namespace for the Kubernetes object.
Type: String
ResourceVersion:
Type: String
Description: >-
This is the resource version for the Kubernetes object.
ResourceName:
Description: >-
This is the resource name for the Kubernetes object
Type: String
AutoMinorVersionUpgrade:
Description: >-
Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window.
Type: String
Default: false
AZMode:
Description: >-
For Memcached cache clusters, indicates whether the nodes are created in a single Availability Zone or across multiple Availability Zones in the cluster's region.
Type: String
CacheNodeType:
Description: >-
The compute and memory capacity of nodes in a cache cluster.
https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html
Type: String
Default: cache.m5.large
CacheParameterGroupName:
Description: >-
The name of the cache parameter group that is associated with this cache cluster.
Type: String
CacheSubnetGroupName:
Description: >-
The cache subnet group that you associate with a cache cluster.
"Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property."
Type: String
ClusterName:
Description: >-
This is the cluster name for the operator
Type: String
Engine:
Description: >-
The name of the cache engine to be used for this cache cluster, such as memcached or redis.
Type: String
Default: "redis"
EngineVersion:
Description: >-
The version of the cache engine to be used for this cluster.
Type: String
Default: "5.0.0"
NotificationTopicArn:
Description: >-
The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent.
Type: String
NumCacheNodes:
Description: >-
The number of cache nodes that the cache cluster should have.
Type: Number
Default: "1"
Port:
Description: >-
The port number on which each of the cache nodes will accept connections.
Type: Number
PreferredMaintenanceWindow:
Description: >-
The weekly time range (in UTC) during which system maintenance can occur.
Type: String
Default: mon:05:00-mon:09:00
PreferredAvailabilityZone:
Description: >-
The Amazon EC2 Availability Zone in which the cache cluster is created.
Type: String
PreferredAvailabilityZones:
Description: >-
For Memcached cache clusters, the list of Availability Zones in which cache nodes are created. The number of Availability Zones listed must equal the number of cache nodes. For example, if you want to create three nodes in two different Availability Zones, you can specify ["us-east-1a", "us-east-1a", "us-east-1b"], which would create two nodes in us-east-1a and one node in us-east-1b.
Type: CommaDelimitedList
SnapshotWindow:
Description: >-
For Redis cache clusters, the daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your node group. For example, you can specify 05:00-09:00.
Type: String
Default: "05:00-09:00"
VpcSecurityGroupIds:
Description: >-
A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead.
Type: CommaDelimitedList
Conditions:
IsRedis:
!Equals [!Ref Engine, "redis"]
IsMemcached:
!Equals [!Ref Engine, "memcached"]
HasAZMode:
!Not [!Equals [!Ref AZMode, ""]]
HasPreferredAvailabilityZones:
!Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]]
HasPreferredAvailabilityZone:
!Not [!Equals [!Ref PreferredAvailabilityZone, ""]]
HasVpcSecurityGroupIds:
!Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]]
Resources:
ElastiCacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
AZMode:
!If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"]
CacheNodeType: !Ref CacheNodeType
CacheParameterGroupName: !Ref CacheParameterGroupName
CacheSubnetGroupName: !Ref CacheSubnetGroupName
ClusterName: !Ref ClusterName
Engine: !Ref Engine
EngineVersion: !Ref EngineVersion
NumCacheNodes: !Ref NumCacheNodes
Port: !Ref Port
PreferredAvailabilityZone:
!If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"]
PreferredAvailabilityZones:
!If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"]
PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow
SnapshotWindow: !Ref SnapshotWindow
Tags:
- Key: Namespace
Value: !Ref Namespace
- Key: ResourceVersion
Value: !Ref ResourceVersion
- Key: ResourceName
Value: !Ref ResourceName
- Key: ClusterName
Value: !Ref ClusterName
- Key: Heritage
Value: operator.aws
VpcSecurityGroupIds:
!If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"]
Outputs:
RedisEndpointAddress:
Value: !GetAtt
- ElastiCacheCluster
- RedisEndpoint.Address
Condition: IsRedis
Description: The DNS address of the configuration endpoint for the Redis cache cluster.
RedisEndpointPort:
Value: !GetAtt
- ElastiCacheCluster
- RedisEndpoint.Port
Condition: IsRedis
Description: The port number of the configuration endpoint for the Redis cache cluster.
ConfigurationEndpointAddress:
Value: !GetAtt
- ElastiCacheCluster
- ConfigurationEndpoint.Address
Condition: IsMemcached
Description: The DNS address of the configuration endpoint for the Memcached cache cluster.
ConfigurationEndpointPort:
Value: !GetAtt
- ElastiCacheCluster
- ConfigurationEndpoint.Port
Condition: IsMemcached
Description: The port number of the configuration endpoint for the Memcached cache cluster.
2 changes: 1 addition & 1 deletion cmd/aws-service-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "us-west-2", "AWS Region for resources to be created in")
rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "Info", "Log level for the CLI")
rootCmd.PersistentFlags().StringVarP(&logFile, "logfile", "", "", "Log file for the CLI")
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,s3bucket,snssubscription,snstopic,sqsqueue", "Comma delimited list of CRDs to deploy")
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,elasticache,s3bucket,snssubscription,snstopic,sqsqueue", "Comma delimited list of CRDs to deploy")
rootCmd.PersistentFlags().StringVarP(&clusterName, "cluster-name", "i", "aws-operator", "Cluster name for the Application to run as, used to label the Cloudformation templated to avoid conflict")
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")
Expand Down
1 change: 1 addition & 0 deletions code-generation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ install-bindata:
.PHONY: update-bindata
update-bindata:
go generate ./pkg/codegen/
go fmt ./...

.PHONY: rebuild
rebuild: update-bindata build
2 changes: 1 addition & 1 deletion code-generation/pkg/codegen/assets/operator.go.templ
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func syncAdditionalResources(config config.Config, s *awsV1alpha1.{{.Spec.Kind}}
{{ if .Spec.AdditionalResources.Services }}services := []string{}{{end}}
{{- range $resource := .Spec.AdditionalResources.Services }}
{{- if eq $resource.Type "ExternalName"}}
{{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", {{(index $resource.Ports 0).Port}})
{{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", "{{(index $resource.Ports 0).Port}}")
services = append(services, {{$resource.Name}})
{{- end}}
{{- end}}
Expand Down
2 changes: 1 addition & 1 deletion code-generation/pkg/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func createFile(rootPath string, fileName string, templateName string, path stri
if templateName[len(templateName)-3:] == ".go" {
formatted, err = format.Source(bf.Bytes())
if err != nil {
log.Fatalf("Error formatting resolved template: %+v", err)
log.Fatalf("Error formatting resolved template %s: %+v", templateName, err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion configs/aws-service-operator-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Resources:
"cloudformation:*",
"ecr:*",
"dynamodb:*",
"s3:*"
"s3:*",
"elasticache:*"
],
"Resource": "*"
}
Expand Down
168 changes: 168 additions & 0 deletions examples/cloudformationtemplates/elasticache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
apiVersion: service-operator.aws/v1alpha1
kind: CloudFormationTemplate
metadata:
name: elasticache
data:
key: elasticache.yaml
template: |
AWSTemplateFormatVersion: "2010-09-09"
Description: 'AWS Operator - Amazon Elasticache Cluster'
Parameters:
Namespace:
Description: >-
This is the namespace for the Kubernetes object.
Type: String
ResourceVersion:
Type: String
Description: >-
This is the resource version for the Kubernetes object.
ResourceName:
Description: >-
This is the resource name for the Kubernetes object
Type: String
AutoMinorVersionUpgrade:
Description: >-
Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window.
Type: String
Default: false
AZMode:
Description: >-
For Memcached cache clusters, indicates whether the nodes are created in a single Availability Zone or across multiple Availability Zones in the cluster's region.
Type: String
CacheNodeType:
Description: >-
The compute and memory capacity of nodes in a cache cluster.
https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html
Type: String
Default: cache.m5.large
CacheParameterGroupName:
Description: >-
The name of the cache parameter group that is associated with this cache cluster.
Type: String
CacheSubnetGroupName:
Description: >-
The cache subnet group that you associate with a cache cluster.
"Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property."
Type: String
ClusterName:
Description: >-
This is the cluster name for the operator
Type: String
Engine:
Description: >-
The name of the cache engine to be used for this cache cluster, such as memcached or redis.
Type: String
Default: "redis"
EngineVersion:
Description: >-
The version of the cache engine to be used for this cluster.
Type: String
Default: "5.0.0"
NotificationTopicArn:
Description: >-
The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent.
Type: String
NumCacheNodes:
Description: >-
The number of cache nodes that the cache cluster should have.
Type: Number
Default: "1"
Port:
Description: >-
The port number on which each of the cache nodes will accept connections.
Type: Number
PreferredMaintenanceWindow:
Description: >-
The weekly time range (in UTC) during which system maintenance can occur.
Type: String
Default: mon:05:00-mon:09:00
PreferredAvailabilityZone:
Description: >-
The Amazon EC2 Availability Zone in which the cache cluster is created.
Type: String
PreferredAvailabilityZones:
Description: >-
For Memcached cache clusters, the list of Availability Zones in which cache nodes are created. The number of Availability Zones listed must equal the number of cache nodes. For example, if you want to create three nodes in two different Availability Zones, you can specify ["us-east-1a", "us-east-1a", "us-east-1b"], which would create two nodes in us-east-1a and one node in us-east-1b.
Type: CommaDelimitedList
SnapshotWindow:
Description: >-
For Redis cache clusters, the daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your node group. For example, you can specify 05:00-09:00.
Type: String
Default: "05:00-09:00"
VpcSecurityGroupIds:
Description: >-
A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead.
Type: CommaDelimitedList
Conditions:
IsRedis:
!Equals [!Ref Engine, "redis"]
IsMemcached:
!Equals [!Ref Engine, "memcached"]
HasAZMode:
!Not [!Equals [!Ref AZMode, ""]]
HasPreferredAvailabilityZones:
!Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]]
HasPreferredAvailabilityZone:
!Not [!Equals [!Ref PreferredAvailabilityZone, ""]]
HasVpcSecurityGroupIds:
!Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]]
Resources:
ElastiCacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
AZMode:
!If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"]
CacheNodeType: !Ref CacheNodeType
CacheParameterGroupName: !Ref CacheParameterGroupName
CacheSubnetGroupName: !Ref CacheSubnetGroupName
ClusterName: !Ref ClusterName
Engine: !Ref Engine
EngineVersion: !Ref EngineVersion
NumCacheNodes: !Ref NumCacheNodes
Port: !Ref Port
PreferredAvailabilityZone:
!If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"]
PreferredAvailabilityZones:
!If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"]
PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow
SnapshotWindow: !Ref SnapshotWindow
Tags:
- Key: Namespace
Value: !Ref Namespace
- Key: ResourceVersion
Value: !Ref ResourceVersion
- Key: ResourceName
Value: !Ref ResourceName
- Key: ClusterName
Value: !Ref ClusterName
- Key: Heritage
Value: operator.aws
VpcSecurityGroupIds:
!If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"]
Outputs:
RedisEndpointAddress:
Value: !GetAtt
- ElastiCacheCluster
- RedisEndpoint.Address
Condition: IsRedis
Description: The DNS address of the configuration endpoint for the Redis cache cluster.
RedisEndpointPort:
Value: !GetAtt
- ElastiCacheCluster
- RedisEndpoint.Port
Condition: IsRedis
Description: The port number of the configuration endpoint for the Redis cache cluster.
ConfigurationEndpointAddress:
Value: !GetAtt
- ElastiCacheCluster
- ConfigurationEndpoint.Address
Condition: IsMemcached
Description: The DNS address of the configuration endpoint for the Memcached cache cluster.
ConfigurationEndpointPort:
Value: !GetAtt
- ElastiCacheCluster
- ConfigurationEndpoint.Port
Condition: IsMemcached
Description: The port number of the configuration endpoint for the Memcached cache cluster.
13 changes: 13 additions & 0 deletions examples/elasticache_memcached.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: service-operator.aws/v1alpha1
kind: ElastiCache
metadata:
name: memcached13
spec:
CacheSubnetGroupName: "loadtest-cluster-k8s"
VpcSecurityGroupIds: "sg-0581b94aa3c0db58c, sg-02b6d0034e8c2fa1b"
AutoMinorVersionUpgrade: true
Engine: memcached
EngineVersion: 1.5.10
NumCacheNodes: 1
Port: 11211
CacheNodeType: "cache.m4.large"
Loading

0 comments on commit 31dd9f0

Please sign in to comment.