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

Commit 31dd9f0

Browse files
committed
adding elasticache non-gen code
1 parent 9fcf5ca commit 31dd9f0

File tree

12 files changed

+535
-5
lines changed

12 files changed

+535
-5
lines changed

cloudformation/elasticache.yaml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
Description: 'AWS Operator - Amazon Elasticache Cluster'
3+
Parameters:
4+
Namespace:
5+
Description: >-
6+
This is the namespace for the Kubernetes object.
7+
Type: String
8+
ResourceVersion:
9+
Type: String
10+
Description: >-
11+
This is the resource version for the Kubernetes object.
12+
ResourceName:
13+
Description: >-
14+
This is the resource name for the Kubernetes object
15+
Type: String
16+
AutoMinorVersionUpgrade:
17+
Description: >-
18+
Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window.
19+
Type: String
20+
Default: false
21+
AZMode:
22+
Description: >-
23+
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.
24+
Type: String
25+
CacheNodeType:
26+
Description: >-
27+
The compute and memory capacity of nodes in a cache cluster.
28+
https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html
29+
Type: String
30+
Default: cache.m5.large
31+
CacheParameterGroupName:
32+
Description: >-
33+
The name of the cache parameter group that is associated with this cache cluster.
34+
Type: String
35+
CacheSubnetGroupName:
36+
Description: >-
37+
The cache subnet group that you associate with a cache cluster.
38+
"Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property."
39+
Type: String
40+
ClusterName:
41+
Description: >-
42+
This is the cluster name for the operator
43+
Type: String
44+
Engine:
45+
Description: >-
46+
The name of the cache engine to be used for this cache cluster, such as memcached or redis.
47+
Type: String
48+
Default: "redis"
49+
EngineVersion:
50+
Description: >-
51+
The version of the cache engine to be used for this cluster.
52+
Type: String
53+
Default: "5.0.0"
54+
NotificationTopicArn:
55+
Description: >-
56+
The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent.
57+
Type: String
58+
NumCacheNodes:
59+
Description: >-
60+
The number of cache nodes that the cache cluster should have.
61+
Type: Number
62+
Default: "1"
63+
Port:
64+
Description: >-
65+
The port number on which each of the cache nodes will accept connections.
66+
Type: Number
67+
PreferredMaintenanceWindow:
68+
Description: >-
69+
The weekly time range (in UTC) during which system maintenance can occur.
70+
Type: String
71+
Default: mon:05:00-mon:09:00
72+
PreferredAvailabilityZone:
73+
Description: >-
74+
The Amazon EC2 Availability Zone in which the cache cluster is created.
75+
Type: String
76+
PreferredAvailabilityZones:
77+
Description: >-
78+
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.
79+
Type: CommaDelimitedList
80+
SnapshotWindow:
81+
Description: >-
82+
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.
83+
Type: String
84+
Default: "05:00-09:00"
85+
VpcSecurityGroupIds:
86+
Description: >-
87+
A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead.
88+
Type: CommaDelimitedList
89+
Conditions:
90+
IsRedis:
91+
!Equals [!Ref Engine, "redis"]
92+
IsMemcached:
93+
!Equals [!Ref Engine, "memcached"]
94+
HasAZMode:
95+
!Not [!Equals [!Ref AZMode, ""]]
96+
HasPreferredAvailabilityZones:
97+
!Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]]
98+
HasPreferredAvailabilityZone:
99+
!Not [!Equals [!Ref PreferredAvailabilityZone, ""]]
100+
HasVpcSecurityGroupIds:
101+
!Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]]
102+
Resources:
103+
ElastiCacheCluster:
104+
Type: AWS::ElastiCache::CacheCluster
105+
Properties:
106+
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
107+
AZMode:
108+
!If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"]
109+
CacheNodeType: !Ref CacheNodeType
110+
CacheParameterGroupName: !Ref CacheParameterGroupName
111+
CacheSubnetGroupName: !Ref CacheSubnetGroupName
112+
ClusterName: !Ref ClusterName
113+
Engine: !Ref Engine
114+
EngineVersion: !Ref EngineVersion
115+
NumCacheNodes: !Ref NumCacheNodes
116+
Port: !Ref Port
117+
PreferredAvailabilityZone:
118+
!If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"]
119+
PreferredAvailabilityZones:
120+
!If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"]
121+
PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow
122+
SnapshotWindow: !Ref SnapshotWindow
123+
Tags:
124+
- Key: Namespace
125+
Value: !Ref Namespace
126+
- Key: ResourceVersion
127+
Value: !Ref ResourceVersion
128+
- Key: ResourceName
129+
Value: !Ref ResourceName
130+
- Key: ClusterName
131+
Value: !Ref ClusterName
132+
- Key: Heritage
133+
Value: operator.aws
134+
VpcSecurityGroupIds:
135+
!If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"]
136+
Outputs:
137+
RedisEndpointAddress:
138+
Value: !GetAtt
139+
- ElastiCacheCluster
140+
- RedisEndpoint.Address
141+
Condition: IsRedis
142+
Description: The DNS address of the configuration endpoint for the Redis cache cluster.
143+
RedisEndpointPort:
144+
Value: !GetAtt
145+
- ElastiCacheCluster
146+
- RedisEndpoint.Port
147+
Condition: IsRedis
148+
Description: The port number of the configuration endpoint for the Redis cache cluster.
149+
ConfigurationEndpointAddress:
150+
Value: !GetAtt
151+
- ElastiCacheCluster
152+
- ConfigurationEndpoint.Address
153+
Condition: IsMemcached
154+
Description: The DNS address of the configuration endpoint for the Memcached cache cluster.
155+
ConfigurationEndpointPort:
156+
Value: !GetAtt
157+
- ElastiCacheCluster
158+
- ConfigurationEndpoint.Port
159+
Condition: IsMemcached
160+
Description: The port number of the configuration endpoint for the Memcached cache cluster.

cmd/aws-service-operator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func init() {
5050
rootCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "us-west-2", "AWS Region for resources to be created in")
5151
rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "Info", "Log level for the CLI")
5252
rootCmd.PersistentFlags().StringVarP(&logFile, "logfile", "", "", "Log file for the CLI")
53-
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,s3bucket,snssubscription,snstopic,sqsqueue", "Comma delimited list of CRDs to deploy")
53+
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,elasticache,s3bucket,snssubscription,snstopic,sqsqueue", "Comma delimited list of CRDs to deploy")
5454
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")
5555
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
5656
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")

code-generation/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ install-bindata:
1616
.PHONY: update-bindata
1717
update-bindata:
1818
go generate ./pkg/codegen/
19+
go fmt ./...
1920

2021
.PHONY: rebuild
2122
rebuild: update-bindata build

code-generation/pkg/codegen/assets/operator.go.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func syncAdditionalResources(config config.Config, s *awsV1alpha1.{{.Spec.Kind}}
294294
{{ if .Spec.AdditionalResources.Services }}services := []string{}{{end}}
295295
{{- range $resource := .Spec.AdditionalResources.Services }}
296296
{{- if eq $resource.Type "ExternalName"}}
297-
{{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", {{(index $resource.Ports 0).Port}})
297+
{{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", "{{(index $resource.Ports 0).Port}}")
298298
services = append(services, {{$resource.Name}})
299299
{{- end}}
300300
{{- end}}

code-generation/pkg/codegen/codegen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func createFile(rootPath string, fileName string, templateName string, path stri
196196
if templateName[len(templateName)-3:] == ".go" {
197197
formatted, err = format.Source(bf.Bytes())
198198
if err != nil {
199-
log.Fatalf("Error formatting resolved template: %+v", err)
199+
log.Fatalf("Error formatting resolved template %s: %+v", templateName, err)
200200
}
201201
}
202202

configs/aws-service-operator-role.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Resources:
4747
"cloudformation:*",
4848
"ecr:*",
4949
"dynamodb:*",
50-
"s3:*"
50+
"s3:*",
51+
"elasticache:*"
5152
],
5253
"Resource": "*"
5354
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
apiVersion: service-operator.aws/v1alpha1
2+
kind: CloudFormationTemplate
3+
metadata:
4+
name: elasticache
5+
data:
6+
key: elasticache.yaml
7+
template: |
8+
AWSTemplateFormatVersion: "2010-09-09"
9+
Description: 'AWS Operator - Amazon Elasticache Cluster'
10+
Parameters:
11+
Namespace:
12+
Description: >-
13+
This is the namespace for the Kubernetes object.
14+
Type: String
15+
ResourceVersion:
16+
Type: String
17+
Description: >-
18+
This is the resource version for the Kubernetes object.
19+
ResourceName:
20+
Description: >-
21+
This is the resource name for the Kubernetes object
22+
Type: String
23+
AutoMinorVersionUpgrade:
24+
Description: >-
25+
Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window.
26+
Type: String
27+
Default: false
28+
AZMode:
29+
Description: >-
30+
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.
31+
Type: String
32+
CacheNodeType:
33+
Description: >-
34+
The compute and memory capacity of nodes in a cache cluster.
35+
https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html
36+
Type: String
37+
Default: cache.m5.large
38+
CacheParameterGroupName:
39+
Description: >-
40+
The name of the cache parameter group that is associated with this cache cluster.
41+
Type: String
42+
CacheSubnetGroupName:
43+
Description: >-
44+
The cache subnet group that you associate with a cache cluster.
45+
"Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property."
46+
Type: String
47+
ClusterName:
48+
Description: >-
49+
This is the cluster name for the operator
50+
Type: String
51+
Engine:
52+
Description: >-
53+
The name of the cache engine to be used for this cache cluster, such as memcached or redis.
54+
Type: String
55+
Default: "redis"
56+
EngineVersion:
57+
Description: >-
58+
The version of the cache engine to be used for this cluster.
59+
Type: String
60+
Default: "5.0.0"
61+
NotificationTopicArn:
62+
Description: >-
63+
The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent.
64+
Type: String
65+
NumCacheNodes:
66+
Description: >-
67+
The number of cache nodes that the cache cluster should have.
68+
Type: Number
69+
Default: "1"
70+
Port:
71+
Description: >-
72+
The port number on which each of the cache nodes will accept connections.
73+
Type: Number
74+
PreferredMaintenanceWindow:
75+
Description: >-
76+
The weekly time range (in UTC) during which system maintenance can occur.
77+
Type: String
78+
Default: mon:05:00-mon:09:00
79+
PreferredAvailabilityZone:
80+
Description: >-
81+
The Amazon EC2 Availability Zone in which the cache cluster is created.
82+
Type: String
83+
PreferredAvailabilityZones:
84+
Description: >-
85+
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.
86+
Type: CommaDelimitedList
87+
SnapshotWindow:
88+
Description: >-
89+
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.
90+
Type: String
91+
Default: "05:00-09:00"
92+
VpcSecurityGroupIds:
93+
Description: >-
94+
A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead.
95+
Type: CommaDelimitedList
96+
Conditions:
97+
IsRedis:
98+
!Equals [!Ref Engine, "redis"]
99+
IsMemcached:
100+
!Equals [!Ref Engine, "memcached"]
101+
HasAZMode:
102+
!Not [!Equals [!Ref AZMode, ""]]
103+
HasPreferredAvailabilityZones:
104+
!Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]]
105+
HasPreferredAvailabilityZone:
106+
!Not [!Equals [!Ref PreferredAvailabilityZone, ""]]
107+
HasVpcSecurityGroupIds:
108+
!Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]]
109+
Resources:
110+
ElastiCacheCluster:
111+
Type: AWS::ElastiCache::CacheCluster
112+
Properties:
113+
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
114+
AZMode:
115+
!If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"]
116+
CacheNodeType: !Ref CacheNodeType
117+
CacheParameterGroupName: !Ref CacheParameterGroupName
118+
CacheSubnetGroupName: !Ref CacheSubnetGroupName
119+
ClusterName: !Ref ClusterName
120+
Engine: !Ref Engine
121+
EngineVersion: !Ref EngineVersion
122+
NumCacheNodes: !Ref NumCacheNodes
123+
Port: !Ref Port
124+
PreferredAvailabilityZone:
125+
!If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"]
126+
PreferredAvailabilityZones:
127+
!If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"]
128+
PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow
129+
SnapshotWindow: !Ref SnapshotWindow
130+
Tags:
131+
- Key: Namespace
132+
Value: !Ref Namespace
133+
- Key: ResourceVersion
134+
Value: !Ref ResourceVersion
135+
- Key: ResourceName
136+
Value: !Ref ResourceName
137+
- Key: ClusterName
138+
Value: !Ref ClusterName
139+
- Key: Heritage
140+
Value: operator.aws
141+
VpcSecurityGroupIds:
142+
!If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"]
143+
Outputs:
144+
RedisEndpointAddress:
145+
Value: !GetAtt
146+
- ElastiCacheCluster
147+
- RedisEndpoint.Address
148+
Condition: IsRedis
149+
Description: The DNS address of the configuration endpoint for the Redis cache cluster.
150+
RedisEndpointPort:
151+
Value: !GetAtt
152+
- ElastiCacheCluster
153+
- RedisEndpoint.Port
154+
Condition: IsRedis
155+
Description: The port number of the configuration endpoint for the Redis cache cluster.
156+
ConfigurationEndpointAddress:
157+
Value: !GetAtt
158+
- ElastiCacheCluster
159+
- ConfigurationEndpoint.Address
160+
Condition: IsMemcached
161+
Description: The DNS address of the configuration endpoint for the Memcached cache cluster.
162+
ConfigurationEndpointPort:
163+
Value: !GetAtt
164+
- ElastiCacheCluster
165+
- ConfigurationEndpoint.Port
166+
Condition: IsMemcached
167+
Description: The port number of the configuration endpoint for the Memcached cache cluster.
168+

examples/elasticache_memcached.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: service-operator.aws/v1alpha1
2+
kind: ElastiCache
3+
metadata:
4+
name: memcached13
5+
spec:
6+
CacheSubnetGroupName: "loadtest-cluster-k8s"
7+
VpcSecurityGroupIds: "sg-0581b94aa3c0db58c, sg-02b6d0034e8c2fa1b"
8+
AutoMinorVersionUpgrade: true
9+
Engine: memcached
10+
EngineVersion: 1.5.10
11+
NumCacheNodes: 1
12+
Port: 11211
13+
CacheNodeType: "cache.m4.large"

0 commit comments

Comments
 (0)