Skip to content

Commit 822cc68

Browse files
added maintenance exclusions to GKE (#4197) (#2724)
* added maintenance exclusions to GKE * exclusion name added to the schema * PR comments implemented * spacing corrected in doc Signed-off-by: Modular Magician <[email protected]>
1 parent bc0b75f commit 822cc68

File tree

4 files changed

+176
-4
lines changed

4 files changed

+176
-4
lines changed

.changelog/4197.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
container : added maintenance_exclusions_window to `resource_google_container_cluster`
3+
4+
```

google-beta/resource_container_cluster.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,30 @@ func resourceContainerCluster() *schema.Resource {
572572
},
573573
},
574574
},
575+
"maintenance_exclusion": {
576+
Type: schema.TypeSet,
577+
Optional: true,
578+
MaxItems: 3,
579+
Description: `Exceptions to maintenance window. Non-emergency maintenance should not occur in these windows.`,
580+
Elem: &schema.Resource{
581+
Schema: map[string]*schema.Schema{
582+
"exclusion_name": {
583+
Type: schema.TypeString,
584+
Required: true,
585+
},
586+
"start_time": {
587+
Type: schema.TypeString,
588+
Required: true,
589+
ValidateFunc: validateRFC3339Date,
590+
},
591+
"end_time": {
592+
Type: schema.TypeString,
593+
Required: true,
594+
ValidateFunc: validateRFC3339Date,
595+
},
596+
},
597+
},
598+
},
575599
},
576600
},
577601
},
@@ -2830,6 +2854,16 @@ func expandMaintenancePolicy(d *schema.ResourceData, meta interface{}) *containe
28302854
}
28312855
maintenancePolicy := l[0].(map[string]interface{})
28322856

2857+
if maintenanceExclusions, ok := maintenancePolicy["maintenance_exclusion"]; ok && len(maintenanceExclusions.(*schema.Set).List()) > 0 {
2858+
for _, me := range maintenanceExclusions.(*schema.Set).List() {
2859+
exclusion := me.(map[string]interface{})
2860+
exclusions[exclusion["exclusion_name"].(string)] = containerBeta.TimeWindow{
2861+
StartTime: exclusion["start_time"].(string),
2862+
EndTime: exclusion["end_time"].(string),
2863+
}
2864+
}
2865+
}
2866+
28332867
if dailyMaintenanceWindow, ok := maintenancePolicy["daily_maintenance_window"]; ok && len(dailyMaintenanceWindow.([]interface{})) > 0 {
28342868
dmw := dailyMaintenanceWindow.([]interface{})[0].(map[string]interface{})
28352869
startTime := dmw["start_time"].(string)
@@ -3456,6 +3490,18 @@ func flattenMaintenancePolicy(mp *containerBeta.MaintenancePolicy) []map[string]
34563490
if mp == nil || mp.Window == nil {
34573491
return nil
34583492
}
3493+
3494+
exclusions := []map[string]interface{}{}
3495+
if mp.Window.MaintenanceExclusions != nil {
3496+
for wName, window := range mp.Window.MaintenanceExclusions {
3497+
exclusions = append(exclusions, map[string]interface{}{
3498+
"start_time": window.StartTime,
3499+
"end_time": window.EndTime,
3500+
"exclusion_name": wName,
3501+
})
3502+
}
3503+
}
3504+
34593505
if mp.Window.DailyMaintenanceWindow != nil {
34603506
return []map[string]interface{}{
34613507
{
@@ -3465,6 +3511,7 @@ func flattenMaintenancePolicy(mp *containerBeta.MaintenancePolicy) []map[string]
34653511
"duration": mp.Window.DailyMaintenanceWindow.Duration,
34663512
},
34673513
},
3514+
"maintenance_exclusion": exclusions,
34683515
},
34693516
}
34703517
}
@@ -3478,6 +3525,7 @@ func flattenMaintenancePolicy(mp *containerBeta.MaintenancePolicy) []map[string]
34783525
"recurrence": mp.Window.RecurringWindow.Recurrence,
34793526
},
34803527
},
3528+
"maintenance_exclusion": exclusions,
34813529
},
34823530
}
34833531
}

google-beta/resource_container_cluster_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,38 @@ func TestAccContainerCluster_withRecurringMaintenanceWindow(t *testing.T) {
14211421
})
14221422
}
14231423

1424+
func TestAccContainerCluster_withMaintenanceExclusionWindow(t *testing.T) {
1425+
t.Parallel()
1426+
cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
1427+
resourceName := "google_container_cluster.with_maintenance_exclusion_window"
1428+
1429+
vcrTest(t, resource.TestCase{
1430+
PreCheck: func() { testAccPreCheck(t) },
1431+
Providers: testAccProviders,
1432+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1433+
Steps: []resource.TestStep{
1434+
{
1435+
Config: testAccContainerCluster_withExclusion_RecurringMaintenanceWindow(cluster, "2019-01-01T00:00:00Z", "2019-01-02T00:00:00Z", "2019-05-01T00:00:00Z", "2019-05-02T00:00:00Z"),
1436+
},
1437+
{
1438+
ResourceName: resourceName,
1439+
ImportStateIdPrefix: "us-central1-a/",
1440+
ImportState: true,
1441+
ImportStateVerify: true,
1442+
},
1443+
{
1444+
Config: testAccContainerCluster_withExclusion_DailyMaintenanceWindow(cluster, "2020-01-01T00:00:00Z", "2020-01-02T00:00:00Z", "2020-05-01T00:00:00Z", "2020-05-02T00:00:00Z"),
1445+
},
1446+
{
1447+
ResourceName: resourceName,
1448+
ImportStateIdPrefix: "us-central1-a/",
1449+
ImportState: true,
1450+
ImportStateVerify: true,
1451+
},
1452+
},
1453+
})
1454+
}
1455+
14241456
func TestAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges(t *testing.T) {
14251457
t.Parallel()
14261458

@@ -3650,6 +3682,62 @@ resource "google_container_cluster" "with_recurring_maintenance_window" {
36503682

36513683
}
36523684

3685+
func testAccContainerCluster_withExclusion_RecurringMaintenanceWindow(clusterName string, w1startTime, w1endTime, w2startTime, w2endTime string) string {
3686+
3687+
return fmt.Sprintf(`
3688+
resource "google_container_cluster" "with_maintenance_exclusion_window" {
3689+
name = "%s"
3690+
location = "us-central1-a"
3691+
initial_node_count = 1
3692+
3693+
maintenance_policy {
3694+
recurring_window {
3695+
start_time = "%s"
3696+
end_time = "%s"
3697+
recurrence = "FREQ=DAILY"
3698+
}
3699+
maintenance_exclusion {
3700+
exclusion_name = "batch job"
3701+
start_time = "%s"
3702+
end_time = "%s"
3703+
}
3704+
maintenance_exclusion {
3705+
exclusion_name = "holiday data load"
3706+
start_time = "%s"
3707+
end_time = "%s"
3708+
}
3709+
}
3710+
}
3711+
`, clusterName, w1startTime, w1endTime, w1startTime, w1endTime, w2startTime, w2endTime)
3712+
}
3713+
3714+
func testAccContainerCluster_withExclusion_DailyMaintenanceWindow(clusterName string, w1startTime, w1endTime, w2startTime, w2endTime string) string {
3715+
3716+
return fmt.Sprintf(`
3717+
resource "google_container_cluster" "with_maintenance_exclusion_window" {
3718+
name = "%s"
3719+
location = "us-central1-a"
3720+
initial_node_count = 1
3721+
3722+
maintenance_policy {
3723+
daily_maintenance_window {
3724+
start_time = "03:00"
3725+
}
3726+
maintenance_exclusion {
3727+
exclusion_name = "batch job"
3728+
start_time = "%s"
3729+
end_time = "%s"
3730+
}
3731+
maintenance_exclusion {
3732+
exclusion_name = "holiday data load"
3733+
start_time = "%s"
3734+
end_time = "%s"
3735+
}
3736+
}
3737+
}
3738+
`, clusterName, w1startTime, w1endTime, w2startTime, w2endTime)
3739+
}
3740+
36533741
func testAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges(containerNetName string, clusterName string) string {
36543742
return fmt.Sprintf(`
36553743
resource "google_compute_network" "container_network" {

website/docs/r/container_cluster.html.markdown

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,17 @@ The `authenticator_groups_config` block supports:
449449
* `security_group` - (Required) The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format `[email protected]`.
450450

451451
The `maintenance_policy` block supports:
452+
* `daily_maintenance_window` - (Optional) structure documented below.
453+
* `recurring_window` - (Optional) structure documented below
454+
* `maintenance_exclusion` - (Optional) structure documented below
452455

453-
* `daily_maintenance_window` - (Required in GA, Optional in Beta) Time window specified for daily maintenance operations.
456+
In beta, one or the other of `recurring_window` and `daily_maintenance_window` is required if a `maintenance_policy` block is supplied.
457+
458+
* `daily_maintenance_window` - Time window specified for daily maintenance operations.
454459
Specify `start_time` in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format "HH:MM”,
455460
where HH : \[00-23\] and MM : \[00-59\] GMT. For example:
456461

462+
Examples:
457463
```hcl
458464
maintenance_policy {
459465
daily_maintenance_window {
@@ -462,8 +468,7 @@ maintenance_policy {
462468
}
463469
```
464470

465-
* `recurring_window` - (Optional) Time window for
466-
recurring maintenance operations.
471+
* `recurring_window` - Time window for recurring maintenance operations.
467472

468473
Specify `start_time` and `end_time` in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) "Zulu" date format. The start time's date is
469474
the initial date that the window starts, and the end time is used for calculating duration. Specify `recurrence` in
@@ -491,7 +496,34 @@ maintenance_policy {
491496
}
492497
```
493498

494-
In beta, one or the other of `recurring_window` and `daily_maintenance_window` is required if a `maintenance_policy` block is supplied.
499+
* `maintenance_exclusion` - Exceptions to maintenance window. Non-emergency maintenance should not occur in these windows. A cluster can have up to three maintenance exclusions at a time [Maintenance Window and Exclusions](https://cloud.google.com/kubernetes-engine/docs/concepts/maintenance-windows-and-exclusions)
500+
501+
Specify `start_time` and `end_time` in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) "Zulu" date format. The start time's date is
502+
the initial date that the window starts, and the end time is used for calculating duration.Specify `recurrence` in
503+
[RFC5545](https://tools.ietf.org/html/rfc5545#section-3.8.5.3) RRULE format, to specify when this recurs.
504+
Note that GKE may accept other formats, but will return values in UTC, causing a permanent diff.
505+
506+
Examples:
507+
508+
```
509+
maintenance_policy {
510+
recurring_window {
511+
start_time = "2019-01-01T00:00:00Z"
512+
end_time = "2019-01-02T00:00:00Z"
513+
recurrence = "FREQ=DAILY"
514+
}
515+
maintenance_exclusion{
516+
exclusion_name = "batch job"
517+
start_time = "2019-01-01T00:00:00Z"
518+
end_time = "2019-01-02T00:00:00Z"
519+
}
520+
maintenance_exclusion{
521+
exclusion_name = "holiday data load"
522+
start_time = "2019-05-01T00:00:00Z"
523+
end_time = "2019-05-02T00:00:00Z"
524+
}
525+
}
526+
```
495527

496528
The `ip_allocation_policy` block supports:
497529

0 commit comments

Comments
 (0)