Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Redis] add support for data tiering nodes #783

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions aws-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ provision:
type: string
details: AWS Elasticache node type (see https://aws.amazon.com/elasticache/pricing)
default: ""
# `node_type` is required by the provider but we can't specify it as such
# `node_type` is required by the provider, but we can't specify it as such
# in this manifest because we need to support passing `cache_size` without
# any `node_type` for backward compatibility. If `node_type` isn't specified
# in the plan nor at rovisioning time, provisioning will throw this error:
# in the plan nor at provisioning time, provisioning will throw this error:
# "node_type" is required unless "global_replication_group_id"
- field_name: elasticache_subnet_group
type: string
Expand All @@ -94,6 +94,16 @@ provision:
details: Whether to enable encryption at rest.
default: true
prohibit_update: true
- field_name: data_tiering_enabled
type: boolean
details: |
Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type.
This parameter must be set to true when using `r6gd` nodes.
Not all versions of Redis support this feature. Check supported versions.
For more information about Node Types and supported Redis versions see
https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html
default: false
prohibit_update: true
- field_name: kms_key_id
type: string
details: The ARN of the key to use if encrypting at rest. Defaults to AWS managed key.
Expand Down
61 changes: 41 additions & 20 deletions integration-tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import (
)

const (
redisServiceID = "e9c11b1b-0caa-45c9-b9b2-592939c9a5a6"
redisServiceName = "csb-aws-redis"
redisServiceDescription = "Beta - CSB Amazon ElastiCache for Redis - multinode with automatic failover"
redisServiceDisplayName = "CSB Amazon ElastiCache for Redis (Beta)"
redisServiceDocumentationURL = "https://docs.vmware.com/en/Tanzu-Cloud-Service-Broker-for-AWS/1.2/csb-aws/GUID-reference-aws-redis.html"
redisServiceSupportURL = "https://aws.amazon.com/redis/"
redisServiceProviderDisplayName = "VMware"
redisCustomPlanName = "custom-sample"
redisCustomPlanID = "c7f64994-a1d9-4e1f-9491-9d8e56bbf146"
redisServiceID = "e9c11b1b-0caa-45c9-b9b2-592939c9a5a6"
redisServiceName = "csb-aws-redis"
redisServiceDescription = "Beta - CSB Amazon ElastiCache for Redis - multinode with automatic failover"
redisServiceDisplayName = "CSB Amazon ElastiCache for Redis (Beta)"
redisServiceDocumentationURL = "https://docs.vmware.com/en/Tanzu-Cloud-Service-Broker-for-AWS/1.2/csb-aws/GUID-reference-aws-redis.html"
redisServiceSupportURL = "https://aws.amazon.com/redis/"
redisServiceProviderDisplayName = "VMware"
redisCustomPlanName = "custom-sample"
redisCustomPlanID = "c7f64994-a1d9-4e1f-9491-9d8e56bbf146"
deprecatedCacheSizePlanName = "deprecated-cachesize-sample"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Maybe by introducing a new line between redisCustomPlanID and deprecatedCacheSizePlanName go formatter wouldn't try to reformat untouched lines to preserve alignment.

Having git/Github diffs only highlight added/changed lines is a big help when reviewing the code.
However, feel free to leave it as it is. But maybe keep it in mind for future commits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I see you have done some cleanup of the code from cache_size.
I would recommend adding these changes in a different PR to keep this PR focused on the changes needed to make data_tiering work.
Also, feel free to be more strict when reviewing my PRs.
I wouldn't be bothered by you asking me to modify my PR to use less hardcoded strings in tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this PR is small enough that it is ok to leave the cleanup changes in it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecatedCacheSizePlanID = "eeae19c8-00c1-442d-b423-a377684b70df"
redisPlanWithFlexibleNodeTypePlanName = "flexible-nodetype-sample"
redisPlanWithFlexibleNodeTypePlanID = "2deb6c13-7ea1-4bad-a519-0ac9600e9a29"
)

var customRedisPlans = []map[string]any{
Expand All @@ -37,8 +41,8 @@ var customRedisPlan = map[string]any{
}

var redisPlanWithFlexibleNodeType = map[string]any{
"name": "flexible-nodetype-sample",
"id": "2deb6c13-7ea1-4bad-a519-0ac9600e9a29",
"name": redisPlanWithFlexibleNodeTypePlanName,
"id": redisPlanWithFlexibleNodeTypePlanID,
"description": "Beta - An example of a Redis plan for which node_type can be specified at provision time.",
"redis_version": "6.x",
"node_count": 2,
Expand All @@ -48,8 +52,8 @@ var redisPlanWithFlexibleNodeType = map[string]any{
}

var deprecatedCacheSizePlan = map[string]any{
"name": "deprecated-cachesize-sample",
"id": "eeae19c8-00c1-442d-b423-a377684b70df",
"name": deprecatedCacheSizePlanName,
"id": deprecatedCacheSizePlanID,
"description": "Beta - Redis plan with deprecated cache_size",
"cache_size": 2,
"redis_version": "6.x",
Expand Down Expand Up @@ -88,12 +92,12 @@ var _ = Describe("Redis", Label("Redis"), func() {
ID: Equal("c7f64994-a1d9-4e1f-9491-9d8e56bbf146"),
}),
MatchFields(IgnoreExtras, Fields{
Name: Equal("deprecated-cachesize-sample"),
ID: Equal("eeae19c8-00c1-442d-b423-a377684b70df"),
Name: Equal(deprecatedCacheSizePlanName),
ID: Equal(deprecatedCacheSizePlanID),
}),
MatchFields(IgnoreExtras, Fields{
Name: Equal("flexible-nodetype-sample"),
ID: Equal("2deb6c13-7ea1-4bad-a519-0ac9600e9a29"),
Name: Equal(redisPlanWithFlexibleNodeTypePlanName),
ID: Equal(redisPlanWithFlexibleNodeTypePlanID),
}),
),
)
Expand Down Expand Up @@ -164,12 +168,12 @@ var _ = Describe("Redis", Label("Redis"), func() {
)

It("should prevent passing the deprecated property `cache_size` as user input", func() {
_, err := broker.Provision(redisServiceName, "custom-sample", map[string]any{"cache_size": 2})
_, err := broker.Provision(redisServiceName, redisCustomPlanName, map[string]any{"cache_size": 2})
Expect(err).To(MatchError(ContainSubstring("additional properties are not allowed: cache_size")))
})

It("should keeping working as before for existing customers relying on `cache_size` property", func() {
_, err := broker.Provision(redisServiceName, "deprecated-cachesize-sample", map[string]any{})
_, err := broker.Provision(redisServiceName, deprecatedCacheSizePlanName, map[string]any{})
Expect(err).NotTo(HaveOccurred())

Expect(mockTerraform.FirstTerraformInvocationVars()).To(
Expand All @@ -179,7 +183,7 @@ var _ = Describe("Redis", Label("Redis"), func() {
})

It("should keeping working as before for existing customers relying on `cache_size` property and per-instance `node_type`", func() {
_, err := broker.Provision(redisServiceName, "deprecated-cachesize-sample", map[string]any{"node_type": "cache.t2.micro"})
_, err := broker.Provision(redisServiceName, deprecatedCacheSizePlanName, map[string]any{"node_type": "cache.t2.micro"})
Expect(err).NotTo(HaveOccurred())

Expect(mockTerraform.FirstTerraformInvocationVars()).To(
Expand Down Expand Up @@ -214,6 +218,7 @@ var _ = Describe("Redis", Label("Redis"), func() {
HaveKeyWithValue("maintenance_start_min", BeNil()),
HaveKeyWithValue("maintenance_end_hour", BeNil()),
HaveKeyWithValue("maintenance_end_min", BeNil()),
HaveKeyWithValue("data_tiering_enabled", BeFalse()),
))
})

Expand Down Expand Up @@ -260,6 +265,21 @@ var _ = Describe("Redis", Label("Redis"), func() {
),
)
})

It("`data_tiering_enabled` must be set to true when using `r6gd` nodes when provisioning", func() {
_, err := broker.Provision(redisServiceName, redisPlanWithFlexibleNodeTypePlanName, map[string]any{
"node_type": "cache.r6gd.xlarge",
"data_tiering_enabled": true,
})
Expect(err).NotTo(HaveOccurred())

Expect(mockTerraform.FirstTerraformInvocationVars()).To(
SatisfyAll(
HaveKeyWithValue("node_type", "cache.r6gd.xlarge"),
HaveKeyWithValue("data_tiering_enabled", true),
),
)
})
})

Describe("updating instance", func() {
Expand Down Expand Up @@ -290,6 +310,7 @@ var _ = Describe("Redis", Label("Redis"), func() {
Entry("instance_name", "instance_name", "any-valid-instance-name"),
Entry("at_rest_encryption_enabled", "at_rest_encryption_enabled", false),
Entry("kms_key_id", "kms_key_id", "fake-encryption-at-rest-key"),
Entry("data_tiering_enabled", "data_tiering_enabled", true),
)

It("preventing updates for `plan defined properties` by design", func() {
Expand Down
2 changes: 2 additions & 0 deletions terraform-tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
"maintenance_end_min": nil,
"maintenance_start_min": nil,
"maintenance_day": nil,
"data_tiering_enabled": false,
}

BeforeAll(func() {
Expand Down Expand Up @@ -87,6 +88,7 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
"snapshot_arns": BeNil(),
"tags_all": BeAssignableToTypeOf(map[string]any{}),
"user_group_ids": BeNil(),
"data_tiering_enabled": BeFalse(),
}))
})
})
Expand Down
1 change: 1 addition & 0 deletions terraform/redis/cluster/provision/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ resource "aws_elasticache_replication_group" "redis" {
at_rest_encryption_enabled = var.at_rest_encryption_enabled
kms_key_id = var.kms_key_id
maintenance_window = local.maintenance_window
data_tiering_enabled = var.data_tiering_enabled

lifecycle {
prevent_destroy = true
Expand Down
1 change: 1 addition & 0 deletions terraform/redis/cluster/provision/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ variable "maintenance_start_hour" { type = string }
variable "maintenance_start_min" { type = string }
variable "maintenance_end_hour" { type = string }
variable "maintenance_end_min" { type = string }
variable "data_tiering_enabled" { type = bool }