Skip to content

Commit 477453a

Browse files
harshitpatel-githubHarshit Patel
authored andcommitted
Redis Cluster maintenance policy and schedule addition (GoogleCloudPlatform#11574)
Co-authored-by: Harshit Patel <[email protected]>
1 parent 6145298 commit 477453a

File tree

4 files changed

+184
-11
lines changed

4 files changed

+184
-11
lines changed

mmv1/products/redis/Cluster.yaml

+118
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,121 @@ properties:
276276
Configure Redis Cluster behavior using a subset of native Redis configuration parameters.
277277
Please check Memorystore documentation for the list of supported parameters:
278278
https://cloud.google.com/memorystore/docs/cluster/supported-instance-configurations
279+
- !ruby/object:Api::Type::NestedObject
280+
name: maintenancePolicy
281+
description: Maintenance policy for a cluster
282+
properties:
283+
- !ruby/object:Api::Type::String
284+
name: 'createTime'
285+
output: true
286+
description: |
287+
Output only. The time when the policy was created.
288+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
289+
resolution and up to nine fractional digits.
290+
- !ruby/object:Api::Type::String
291+
name: 'updateTime'
292+
output: true
293+
description: |
294+
Output only. The time when the policy was last updated.
295+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
296+
resolution and up to nine fractional digits.
297+
- !ruby/object:Api::Type::Array
298+
name: 'weeklyMaintenanceWindow'
299+
description: |
300+
Optional. Maintenance window that is applied to resources covered by this policy.
301+
Minimum 1. For the current version, the maximum number
302+
of weekly_window is expected to be one.
303+
item_type: !ruby/object:Api::Type::NestedObject
304+
properties:
305+
- !ruby/object:Api::Type::Enum
306+
name: 'day'
307+
required: true
308+
description: |
309+
Required. The day of week that maintenance updates occur.
310+
311+
- DAY_OF_WEEK_UNSPECIFIED: The day of the week is unspecified.
312+
- MONDAY: Monday
313+
- TUESDAY: Tuesday
314+
- WEDNESDAY: Wednesday
315+
- THURSDAY: Thursday
316+
- FRIDAY: Friday
317+
- SATURDAY: Saturday
318+
- SUNDAY: Sunday
319+
values:
320+
- :DAY_OF_WEEK_UNSPECIFIED
321+
- :MONDAY
322+
- :TUESDAY
323+
- :WEDNESDAY
324+
- :THURSDAY
325+
- :FRIDAY
326+
- :SATURDAY
327+
- :SUNDAY
328+
- !ruby/object:Api::Type::String
329+
name: 'duration'
330+
output: true
331+
description: |
332+
Output only. Duration of the maintenance window.
333+
The current window is fixed at 1 hour.
334+
A duration in seconds with up to nine fractional digits,
335+
terminated by 's'. Example: "3.5s".
336+
- !ruby/object:Api::Type::NestedObject
337+
name: 'startTime'
338+
required: true
339+
allow_empty_object: true
340+
send_empty_value: true
341+
description: |
342+
Required. Start time of the window in UTC time.
343+
properties:
344+
- !ruby/object:Api::Type::Integer
345+
name: 'hours'
346+
description: |
347+
Hours of day in 24 hour format. Should be from 0 to 23.
348+
An API may choose to allow the value "24:00:00" for scenarios like business closing time.
349+
validation: !ruby/object:Provider::Terraform::Validation
350+
function: 'validation.IntBetween(0,23)'
351+
- !ruby/object:Api::Type::Integer
352+
name: 'minutes'
353+
description: |
354+
Minutes of hour of day. Must be from 0 to 59.
355+
validation: !ruby/object:Provider::Terraform::Validation
356+
function: 'validation.IntBetween(0,59)'
357+
- !ruby/object:Api::Type::Integer
358+
name: 'seconds'
359+
description: |
360+
Seconds of minutes of the time. Must normally be from 0 to 59.
361+
An API may allow the value 60 if it allows leap-seconds.
362+
validation: !ruby/object:Provider::Terraform::Validation
363+
function: 'validation.IntBetween(0,60)'
364+
- !ruby/object:Api::Type::Integer
365+
name: 'nanos'
366+
description: |
367+
Fractions of seconds in nanoseconds. Must be from 0 to 999,999,999.
368+
validation: !ruby/object:Provider::Terraform::Validation
369+
function: 'validation.IntBetween(0,999999999)'
370+
- !ruby/object:Api::Type::NestedObject
371+
name: maintenanceSchedule
372+
output: true
373+
description: Upcoming maintenance schedule.
374+
properties:
375+
- !ruby/object:Api::Type::String
376+
name: 'startTime'
377+
output: true
378+
description: |
379+
Output only. The start time of any upcoming scheduled maintenance for this cluster.
380+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
381+
resolution and up to nine fractional digits.
382+
- !ruby/object:Api::Type::String
383+
name: 'endTime'
384+
output: true
385+
description: |
386+
Output only. The end time of any upcoming scheduled maintenance for this cluster.
387+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
388+
resolution and up to nine fractional digits.
389+
- !ruby/object:Api::Type::String
390+
name: 'scheduleDeadlineTime'
391+
output: true
392+
description: |
393+
Output only. The deadline that the maintenance schedule start time
394+
can not go beyond, including reschedule.
395+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond
396+
resolution and up to nine fractional digits.

mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" {
1717
zone_distribution_config {
1818
mode = "MULTI_ZONE"
1919
}
20+
maintenance_policy {
21+
weekly_maintenance_window {
22+
day = "MONDAY"
23+
start_time {
24+
hours = 1
25+
minutes = 0
26+
seconds = 0
27+
nanos = 0
28+
}
29+
}
30+
}
2031
depends_on = [
2132
google_network_connectivity_service_connection_policy.default
2233
]

mmv1/templates/terraform/examples/redis_cluster_ha_single_zone.tf.erb

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" {
99
mode = "SINGLE_ZONE"
1010
zone = "us-central1-f"
1111
}
12+
maintenance_policy {
13+
weekly_maintenance_window {
14+
day = "MONDAY"
15+
start_time {
16+
hours = 1
17+
minutes = 0
18+
seconds = 0
19+
nanos = 0
20+
}
21+
}
22+
}
1223
deletion_protection_enabled = <%= ctx[:vars]['deletion_protection_enabled'] == 'true' %>
1324
depends_on = [
1425
google_network_connectivity_service_connection_policy.default

mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go.erb

+44-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
2424
Steps: []resource.TestStep{
2525
{
2626
// create cluster with replica count 1
27-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE"}),
27+
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}),
2828
},
2929
{
3030
ResourceName: "google_redis_cluster.test",
@@ -34,7 +34,7 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
3434
},
3535
{
3636
// clean up the resource
37-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: false, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE"}),
37+
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}),
3838
},
3939
},
4040
})
@@ -83,7 +83,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
8383
Steps: []resource.TestStep{
8484
{
8585
// create cluster with replica count 1
86-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
86+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
8787
},
8888
{
8989
ResourceName: "google_redis_cluster.test",
@@ -93,7 +93,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
9393
},
9494
{
9595
// update replica count to 2
96-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 2, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
96+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 2, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
9797
},
9898
{
9999
ResourceName: "google_redis_cluster.test",
@@ -103,7 +103,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
103103
},
104104
{
105105
// update replica count to 0
106-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
106+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
107107
},
108108
{
109109
ResourceName: "google_redis_cluster.test",
@@ -113,7 +113,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
113113
},
114114
{
115115
// clean up the resource
116-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE"}),
116+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 0, shardCount: 3, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
117117
},
118118
},
119119
})
@@ -132,7 +132,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
132132
Steps: []resource.TestStep{
133133
{
134134
// create cluster with shard count 3
135-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
135+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
136136
},
137137
{
138138
ResourceName: "google_redis_cluster.test",
@@ -142,7 +142,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
142142
},
143143
{
144144
// update shard count to 5
145-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE"}),
145+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: true, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
146146
},
147147
{
148148
ResourceName: "google_redis_cluster.test",
@@ -152,7 +152,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
152152
},
153153
{
154154
// clean up the resource
155-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE"}),
155+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 5, deletionProtectionEnabled: false, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
156156
},
157157
},
158158
})
@@ -175,6 +175,11 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
175175
name: name,
176176
shardCount: 3,
177177
zoneDistributionMode: "MULTI_ZONE",
178+
maintenanceDay: "MONDAY",
179+
maintenanceHours: 1,
180+
maintenanceMinutes: 0,
181+
maintenanceSeconds: 0,
182+
maintenanceNanos: 0,
178183
redisConfigs: map[string]string{
179184
"maxmemory-policy": "volatile-ttl",
180185
}}),
@@ -191,6 +196,11 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
191196
name: name,
192197
shardCount: 3,
193198
zoneDistributionMode: "MULTI_ZONE",
199+
maintenanceDay: "MONDAY",
200+
maintenanceHours: 1,
201+
maintenanceMinutes: 0,
202+
maintenanceSeconds: 0,
203+
maintenanceNanos: 0,
194204
redisConfigs: map[string]string{
195205
"maxmemory-policy": "allkeys-lru",
196206
"maxmemory-clients": "90%",
@@ -204,7 +214,7 @@ func TestAccRedisCluster_updateRedisConfigs(t *testing.T) {
204214
},
205215
{
206216
// remove all redis configs
207-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, shardCount: 3, zoneDistributionMode: "MULTI_ZONE"}),
217+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, shardCount: 3, zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
208218
},
209219

210220
},
@@ -260,6 +270,11 @@ type ClusterParams struct {
260270
redisConfigs map[string]string
261271
zoneDistributionMode string
262272
zone string
273+
maintenanceDay string
274+
maintenanceHours int
275+
maintenanceMinutes int
276+
maintenanceSeconds int
277+
maintenanceNanos int
263278
}
264279

265280
func createOrUpdateRedisCluster(params *ClusterParams) string {
@@ -278,6 +293,23 @@ func createOrUpdateRedisCluster(params *ClusterParams) string {
278293
`, params.zoneDistributionMode, params.zone)
279294
}
280295

296+
maintenancePolicyBlock := ``
297+
if params.maintenanceDay != "" {
298+
maintenancePolicyBlock = fmt.Sprintf(`
299+
maintenance_policy {
300+
weekly_maintenance_window {
301+
day = "%s"
302+
start_time {
303+
hours = %d
304+
minutes = %d
305+
seconds = %d
306+
nanos = %d
307+
}
308+
}
309+
}
310+
`, params.maintenanceDay, params.maintenanceHours, params.maintenanceMinutes, params.maintenanceSeconds, params.maintenanceNanos)
311+
}
312+
281313
return fmt.Sprintf(`
282314
resource "google_redis_cluster" "test" {
283315
provider = google-beta
@@ -293,6 +325,7 @@ resource "google_redis_cluster" "test" {
293325
redis_configs = {
294326
%s
295327
}
328+
%s
296329
%s
297330
depends_on = [
298331
google_network_connectivity_service_connection_policy.default
@@ -324,7 +357,7 @@ resource "google_compute_network" "producer_net" {
324357
name = "%s"
325358
auto_create_subnetworks = false
326359
}
327-
`, params.name, params.replicaCount, params.shardCount, params.nodeType, params.deletionProtectionEnabled, strBuilder.String(), zoneDistributionConfigBlock, params.name, params.name, params.name)
360+
`, params.name, params.replicaCount, params.shardCount, params.nodeType, params.deletionProtectionEnabled, strBuilder.String(), zoneDistributionConfigBlock, maintenancePolicyBlock, params.name, params.name, params.name)
328361
}
329362

330363
<% end -%>

0 commit comments

Comments
 (0)