Skip to content

Commit

Permalink
Redis Cluster maintenance policy and schedule addition (GoogleCloudPl…
Browse files Browse the repository at this point in the history
…atform#11574)

Co-authored-by: Harshit Patel <[email protected]>
  • Loading branch information
harshitpatel-github and Harshit Patel authored Sep 2, 2024
1 parent 692bae2 commit 2fde08a
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 11 deletions.
118 changes: 118 additions & 0 deletions mmv1/products/redis/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,121 @@ properties:
Configure Redis Cluster behavior using a subset of native Redis configuration parameters.
Please check Memorystore documentation for the list of supported parameters:
https://cloud.google.com/memorystore/docs/cluster/supported-instance-configurations
- !ruby/object:Api::Type::NestedObject
name: maintenancePolicy
description: Maintenance policy for a cluster
properties:
- !ruby/object:Api::Type::String
name: 'createTime'
output: true
description: |
Output only. The time when the policy was created.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
resolution and up to nine fractional digits.
- !ruby/object:Api::Type::String
name: 'updateTime'
output: true
description: |
Output only. The time when the policy was last updated.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
resolution and up to nine fractional digits.
- !ruby/object:Api::Type::Array
name: 'weeklyMaintenanceWindow'
description: |
Optional. Maintenance window that is applied to resources covered by this policy.
Minimum 1. For the current version, the maximum number
of weekly_window is expected to be one.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Enum
name: 'day'
required: true
description: |
Required. The day of week that maintenance updates occur.
- DAY_OF_WEEK_UNSPECIFIED: The day of the week is unspecified.
- MONDAY: Monday
- TUESDAY: Tuesday
- WEDNESDAY: Wednesday
- THURSDAY: Thursday
- FRIDAY: Friday
- SATURDAY: Saturday
- SUNDAY: Sunday
values:
- :DAY_OF_WEEK_UNSPECIFIED
- :MONDAY
- :TUESDAY
- :WEDNESDAY
- :THURSDAY
- :FRIDAY
- :SATURDAY
- :SUNDAY
- !ruby/object:Api::Type::String
name: 'duration'
output: true
description: |
Output only. Duration of the maintenance window.
The current window is fixed at 1 hour.
A duration in seconds with up to nine fractional digits,
terminated by 's'. Example: "3.5s".
- !ruby/object:Api::Type::NestedObject
name: 'startTime'
required: true
allow_empty_object: true
send_empty_value: true
description: |
Required. Start time of the window in UTC time.
properties:
- !ruby/object:Api::Type::Integer
name: 'hours'
description: |
Hours of day in 24 hour format. Should be from 0 to 23.
An API may choose to allow the value "24:00:00" for scenarios like business closing time.
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntBetween(0,23)'
- !ruby/object:Api::Type::Integer
name: 'minutes'
description: |
Minutes of hour of day. Must be from 0 to 59.
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntBetween(0,59)'
- !ruby/object:Api::Type::Integer
name: 'seconds'
description: |
Seconds of minutes of the time. Must normally be from 0 to 59.
An API may allow the value 60 if it allows leap-seconds.
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntBetween(0,60)'
- !ruby/object:Api::Type::Integer
name: 'nanos'
description: |
Fractions of seconds in nanoseconds. Must be from 0 to 999,999,999.
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntBetween(0,999999999)'
- !ruby/object:Api::Type::NestedObject
name: maintenanceSchedule
output: true
description: Upcoming maintenance schedule.
properties:
- !ruby/object:Api::Type::String
name: 'startTime'
output: true
description: |
Output only. The start time of any upcoming scheduled maintenance for this cluster.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
resolution and up to nine fractional digits.
- !ruby/object:Api::Type::String
name: 'endTime'
output: true
description: |
Output only. The end time of any upcoming scheduled maintenance for this cluster.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
resolution and up to nine fractional digits.
- !ruby/object:Api::Type::String
name: 'scheduleDeadlineTime'
output: true
description: |
Output only. The deadline that the maintenance schedule start time
can not go beyond, including reschedule.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
resolution and up to nine fractional digits.
11 changes: 11 additions & 0 deletions mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" {
zone_distribution_config {
mode = "MULTI_ZONE"
}
maintenance_policy {
weekly_maintenance_window {
day = "MONDAY"
start_time {
hours = 1
minutes = 0
seconds = 0
nanos = 0
}
}
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" {
mode = "SINGLE_ZONE"
zone = "us-central1-f"
}
maintenance_policy {
weekly_maintenance_window {
day = "MONDAY"
start_time {
hours = 1
minutes = 0
seconds = 0
nanos = 0
}
}
}
deletion_protection_enabled = <%= ctx[:vars]['deletion_protection_enabled'] == 'true' %>
depends_on = [
google_network_connectivity_service_connection_policy.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
Steps: []resource.TestStep{
{
// create cluster with replica count 1
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -34,7 +34,7 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: false, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: false, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
},
})
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
Steps: []resource.TestStep{
{
// create cluster with replica count 1
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -93,7 +93,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
},
{
// update replica count to 2
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 2, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 2, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -103,7 +103,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
},
{
// update replica count to 0
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -113,7 +113,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
},
})
Expand All @@ -132,7 +132,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
Steps: []resource.TestStep{
{
// create cluster with shard count 3
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -142,7 +142,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
},
{
// update shard count to 5
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
{
ResourceName: "google_redis_cluster.test",
Expand All @@ -152,7 +152,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},
},
})
Expand All @@ -175,6 +175,11 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
name: name,
shardCount: 3,
zoneDistributionMode: "MULTI_ZONE",
maintenanceDay: "MONDAY",
maintenanceHours: 1,
maintenanceMinutes: 0,
maintenanceSeconds: 0,
maintenanceNanos: 0,
redisConfigs: map[string]string{
"maxmemory-policy": "volatile-ttl",
}}),
Expand All @@ -191,6 +196,11 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
name: name,
shardCount: 3,
zoneDistributionMode: "MULTI_ZONE",
maintenanceDay: "MONDAY",
maintenanceHours: 1,
maintenanceMinutes: 0,
maintenanceSeconds: 0,
maintenanceNanos: 0,
redisConfigs: map[string]string{
"maxmemory-policy": "allkeys-lru",
"maxmemory-clients": "90%",
Expand All @@ -204,7 +214,7 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
},
{
// remove all redis configs
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, shardCount: 3, zoneDistributionMode: "MULTI_ZONE"}),
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, shardCount: 3, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
},

},
Expand Down Expand Up @@ -260,6 +270,11 @@ type ClusterParams struct {
redisConfigs map[string]string
zoneDistributionMode string
zone string
maintenanceDay string
maintenanceHours int
maintenanceMinutes int
maintenanceSeconds int
maintenanceNanos int
}

func createOrUpdateRedisCluster(params *ClusterParams) string {
Expand All @@ -278,6 +293,23 @@ func createOrUpdateRedisCluster(params *ClusterParams) string {
`, params.zoneDistributionMode, params.zone)
}

maintenancePolicyBlock := ``
if params.maintenanceDay != "" {
maintenancePolicyBlock = fmt.Sprintf(`
maintenance_policy {
weekly_maintenance_window {
day = "%s"
start_time {
hours = %d
minutes = %d
seconds = %d
nanos = %d
}
}
}
`, params.maintenanceDay, params.maintenanceHours, params.maintenanceMinutes, params.maintenanceSeconds, params.maintenanceNanos)
}

return fmt.Sprintf(`
resource "google_redis_cluster" "test" {
provider = google-beta
Expand All @@ -293,6 +325,7 @@ resource "google_redis_cluster" "test" {
redis_configs = {
%s
}
%s
%s
depends_on = [
google_network_connectivity_service_connection_policy.default
Expand Down Expand Up @@ -324,7 +357,7 @@ resource "google_compute_network" "producer_net" {
name = "%s"
auto_create_subnetworks = false
}
`, params.name, params.replicaCount, params.shardCount, params.nodeType, params.deletionProtectionEnabled, strBuilder.String(), zoneDistributionConfigBlock, params.name, params.name, params.name)
`, params.name, params.replicaCount, params.shardCount, params.nodeType, params.deletionProtectionEnabled, strBuilder.String(), zoneDistributionConfigBlock, maintenancePolicyBlock, params.name, params.name, params.name)
}

<% end -%>

0 comments on commit 2fde08a

Please sign in to comment.