Skip to content

Commit cd7be8b

Browse files
committed
added node pool maintenance policy
1 parent 47f0c03 commit cd7be8b

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,41 @@ var schemaNodePool = map[string]*schema.Schema{
690690
},
691691
},
692692
},
693-
693+
694+
"maintenance_policy": {
695+
Type: schema.TypeList,
696+
Optional: true,
697+
Description: `Maintenance policy for this NodePool.`,
698+
Elem: &schema.Resource{
699+
Schema: map[string]*schema.Schema{
700+
"exclusion_until_end_of_support": {
701+
Type: schema.TypeList,
702+
Optional: true,
703+
Description: `Maintenance exclusion until the end of support.`,
704+
Elem: &schema.Resource{
705+
Schema: map[string]*schema.Schema{
706+
"enabled": {
707+
Type: schema.TypeBool,
708+
Optional: true,
709+
Description: `Whether to enable the maintenance exclusion until the end of support for this NodePool.`,
710+
},
711+
"start_time": {
712+
Type: schema.TypeString,
713+
Computed: true,
714+
Description: `Start time of the maintenance exclusion.`,
715+
},
716+
"end_time": {
717+
Type: schema.TypeString,
718+
Computed: true,
719+
Description: `End time of the maintenance exclusion.`,
720+
},
721+
},
722+
},
723+
},
724+
},
725+
},
726+
},
727+
694728
}
695729

696730
type NodePoolInformation struct {
@@ -1311,6 +1345,19 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool,
13111345
}
13121346
}
13131347

1348+
if v, ok := d.GetOk(prefix + "maintenance_policy"); ok {
1349+
maintenancePolicy := v.([]interface{})[0].(map[string]interface{})
1350+
if v, ok := maintenancePolicy["exclusion_until_end_of_support"]; ok && len(v.([]interface{})) > 0 {
1351+
np.MaintenancePolicy = &container.NodePoolMaintenancePolicy{
1352+
ExclusionUntilEndOfSupport: &container.ExclusionUntilEndOfSupport {},
1353+
}
1354+
exclusionUntilEndOfSupport := v.([]interface{})[0].(map[string]interface{})
1355+
if v, ok := exclusionUntilEndOfSupport["enabled"]; ok {
1356+
np.ExclusionUntilEndOfSupport.Enabled = v.(bool)
1357+
}
1358+
}
1359+
}
1360+
13141361
return np, nil
13151362
}
13161363

@@ -1383,6 +1430,30 @@ func flattenNodePoolNodeDrainConfig(ndc *container.NodeDrainConfig) []map[string
13831430
return []map[string]interface{}{nodeDrainConfig}
13841431
}
13851432

1433+
func flattenExlusionUntilEndOfSupport(ex *container.ExclusionUntilEndOfSupport) []map[string]interface{} {
1434+
if ex == nil {
1435+
return nil
1436+
}
1437+
return []map[string]interface{}{
1438+
{
1439+
"enabled": ex.Enabled,
1440+
"start_time": ex.StartTime,
1441+
"end_time": ex.EndTime,
1442+
},
1443+
}
1444+
}
1445+
1446+
func flattenNodePoolMaintenancePolicy(mp *container.NodePoolMaintenancePolicy) []map[string]interface{} {
1447+
if mp == nil {
1448+
return nil
1449+
}
1450+
1451+
maintenancePolicy := make(map[string]interface{})
1452+
1453+
maintenancePolicy["exclusion_until_end_of_support"] = flattenExlusionUntilEndOfSupport(mp.ExclusionUntilEndOfSupport)
1454+
return []map[string]interface{}{maintenancePolicy}
1455+
}
1456+
13861457
func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *container.NodePool, prefix string) (map[string]interface{}, error) {
13871458
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
13881459
if err != nil {
@@ -1491,6 +1562,10 @@ func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *c
14911562
nodePool["node_drain_config"] = flattenNodePoolNodeDrainConfig(np.NodeDrainConfig)
14921563
}
14931564

1565+
if np.MaintenancePolicy != nil {
1566+
nodePool["maintenance_policy"] = flattenNodePoolMaintenancePolicy(np.MaintenancePolicy)
1567+
}
1568+
14941569
return nodePool, nil
14951570
}
14961571

mmv1/third_party/terraform/services/container/resource_container_node_pool_meta.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ fields:
313313
- field: 'node_config.workload_metadata_config.mode'
314314
api_field: 'config.workloadMetadataConfig.mode'
315315
- api_field: 'nodeDrainConfig.respectPdbDuringNodePoolDeletion'
316+
- api_field: 'maintenancePolicy.exclusionUntilEndOfSupport.enabled'
316317
- field: 'node_count'
317318
provider_only: true
318319
- field: 'node_locations'

mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.tmpl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,34 @@ func TestAccContainerNodePool_withNodeDrainConfig(t *testing.T) {
16261626
})
16271627
}
16281628

1629+
func TestAccContainerNodePool_withMaintenancePolicy(t *testing.T) {
1630+
t.Parallel()
1631+
1632+
cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1633+
nodePool := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10))
1634+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1635+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1636+
1637+
acctest.VcrTest(t, resource.TestCase{
1638+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1639+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1640+
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
1641+
Steps: []resource.TestStep{
1642+
{
1643+
Config: testAccContainerNodePool_withMaintenancePolicy(cluster, nodePool, networkName, subnetworkName),
1644+
Check: resource.ComposeTestCheckFunc(
1645+
resource.TestCheckResourceAttr("google_container_node_pool.np_with_maintenance_policy", "maintenance_policy.0.exclusion_until_end_of_support.0.enabled", "true"),
1646+
),
1647+
},
1648+
{
1649+
ResourceName: "google_container_node_pool.np_with_maintenance_policy",
1650+
ImportState: true,
1651+
ImportStateVerify: true,
1652+
},
1653+
},
1654+
})
1655+
}
1656+
16291657
func TestAccContainerNodePool_withNodeConfigScopeAlias(t *testing.T) {
16301658
t.Parallel()
16311659

@@ -4721,6 +4749,36 @@ resource "google_container_node_pool" "np_with_node_drain_config" {
47214749
`, cluster, networkName, subnetworkName, np)
47224750
}
47234751

4752+
func testAccContainerNodePool_withMaintenancePolicy(cluster, np, networkName, subnetworkName string) string {
4753+
return fmt.Sprintf(`
4754+
data "google_container_engine_versions" "central1a" {
4755+
location = "us-central1-a"
4756+
}
4757+
4758+
resource "google_container_cluster" "cluster" {
4759+
name = "%s"
4760+
location = "us-central1-a"
4761+
initial_node_count = 1
4762+
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
4763+
deletion_protection = false
4764+
network = "%s"
4765+
subnetwork = "%s"
4766+
}
4767+
4768+
resource "google_container_node_pool" "np_with_maintenance_policy" {
4769+
name = "%s"
4770+
location = "us-central1-a"
4771+
cluster = google_container_cluster.cluster.name
4772+
initial_node_count = 1
4773+
maintenance_policy {
4774+
exclusion_until_end_of_support {
4775+
enabled = true
4776+
}
4777+
}
4778+
}
4779+
`, cluster, networkName, subnetworkName, np)
4780+
}
4781+
47244782
func testAccContainerNodePool_version(cluster, np, networkName, subnetworkName string) string {
47254783
return fmt.Sprintf(`
47264784
data "google_container_engine_versions" "central1a" {

mmv1/third_party/terraform/website/docs/r/container_node_pool.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ cluster.
156156

157157
* `node_drain_config` - (Optional) The node drain configuration of the pool. Structure is [documented below](#nested_node_drain_config).
158158

159+
* `maintenance_policy` - (Optional) The maintenance policy of the pool. Structure is [documented below](#nested_maintenance_policy).
160+
159161
* `project` - (Optional) The ID of the project in which to create the node pool. If blank,
160162
the provider-configured project will be used.
161163

@@ -253,6 +255,10 @@ cluster.
253255

254256
* `respect_pdb_during_node_pool_deletion` - (Optional) Whether to respect PodDisruptionBudget policy during node pool deletion.
255257

258+
<a name="nested_maintenance_policy"></a>The `maintenance_policy` block supports:
259+
260+
* `exclusion_until_end_of_support` - (Optional) When enabled, the node pool will not be automatically upgraded by GKE until the node pool version's end of support date.
261+
256262
<a name="nested_upgrade_settings"></a>The `upgrade_settings` block supports:
257263

258264
* `max_surge` - (Optional) The number of additional nodes that can be added to the node pool during

0 commit comments

Comments
 (0)