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

container: Add node_kublet_config support for autopilot clusters #11573

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
26 changes: 26 additions & 0 deletions mmv1/third_party/terraform/services/container/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,22 @@ func schemaNodeConfig() *schema.Schema {
}
}

// Separate since this currently only supports a single value -- a subset of
// the overall NodeKubeletConfig
func schemaNodePoolAutoConfigNodeKubeletConfig() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `Node kubelet configs.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
},
},
}
}

func expandNodeConfigDefaults(configured interface{}) *container.NodeConfigDefaults {
configs := configured.([]interface{})
if len(configs) == 0 || configs[0] == nil {
Expand Down Expand Up @@ -1752,6 +1768,16 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
return result
}

func flattenNodePoolAutoConfigNodeKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
result = append(result, map[string]interface{}{
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
})
}
return result
}

func flattenLinuxNodeConfig(c *container.LinuxNodeConfig) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ func ResourceContainerCluster() *schema.Resource {
Description: `Node pool configs that apply to all auto-provisioned node pools in autopilot clusters and node auto-provisioning enabled clusters.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_kubelet_config": schemaNodePoolAutoConfigNodeKubeletConfig(),
"network_tags": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -4403,6 +4404,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("node_pool_auto_config.0.node_kubelet_config") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNodePoolAutoConfigKubeletConfig: expandKubeletConfig(
d.Get("node_pool_auto_config.0.node_kubelet_config"),
),
},
}

updateF := updateFunc(req, "updating GKE cluster node pool auto config node_kubelet_config parameters")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s node pool auto config node_kubelet_config parameters have been updated", d.Id())
}

if d.HasChange("node_pool_auto_config.0.network_tags.0.tags") {
tags := d.Get("node_pool_auto_config.0.network_tags.0.tags").([]interface{})

Expand Down Expand Up @@ -5737,6 +5756,10 @@ func expandNodePoolAutoConfig(configured interface{}) *container.NodePoolAutoCon
npac := &container.NodePoolAutoConfig{}
config := l[0].(map[string]interface{})

if v, ok := config["node_kubelet_config"]; ok {
npac.NodeKubeletConfig = expandKubeletConfig(v)
}

if v, ok := config["network_tags"]; ok && len(v.([]interface{})) > 0 {
npac.NetworkTags = expandNodePoolAutoConfigNetworkTags(v)
}
Expand Down Expand Up @@ -6575,6 +6598,9 @@ func flattenNodePoolAutoConfig(c *container.NodePoolAutoConfig) []map[string]int
}

result := make(map[string]interface{})
if c.NodeKubeletConfig != nil {
result["node_kubelet_config"] = flattenNodePoolAutoConfigNodeKubeletConfig(c.NodeKubeletConfig)
}
if c.NetworkTags != nil {
result["network_tags"] = flattenNodePoolAutoConfigNetworkTags(c.NetworkTags)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,52 @@ func TestAccContainerCluster_withAutopilotNetworkTags(t *testing.T) {
})
}

func TestAccContainerCluster_withAutopilotKubeletConfig(t *testing.T) {
t.Parallel()

randomSuffix := acctest.RandString(t, 10)
clusterName := fmt.Sprintf("tf-test-cluster-%s", randomSuffix)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAutopilotKubeletConfigBaseline(clusterName),
},
{
ResourceName: "google_container_cluster.with_autopilot_kubelet_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
{
Config: testAccContainerCluster_withAutopilotKubeletConfigUpdates(clusterName, "FALSE"),
},
{
ResourceName: "google_container_cluster.with_autopilot_kubelet_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
{
Config: testAccContainerCluster_withAutopilotKubeletConfigUpdates(clusterName, "TRUE"),
},
{
ResourceName: "google_container_cluster.with_autopilot_kubelet_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
},
})
}


func TestAccContainerCluster_withAutopilotResourceManagerTags(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -10517,6 +10563,37 @@ func testAccContainerCluster_withWorkloadALTSConfigAutopilot(projectID, name str

<% end -%>

func testAccContainerCluster_withAutopilotKubeletConfigBaseline(name string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_autopilot_kubelet_config" {
name = "%s"
location = "us-central1"
initial_node_count = 1
enable_autopilot = true
deletion_protection = false
}
`, name)
}

func testAccContainerCluster_withAutopilotKubeletConfigUpdates(name, insecureKubeletReadonlyPortEnabled string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_autopilot_kubelet_config" {
name = "%s"
location = "us-central1"
initial_node_count = 1

node_pool_auto_config {
node_kubelet_config {
insecure_kubelet_readonly_port_enabled = "%s"
}
}

enable_autopilot = true
deletion_protection = false
}
`, name, insecureKubeletReadonlyPortEnabled)
}

func testAccContainerCluster_resourceManagerTags(projectID, clusterName, networkName, subnetworkName, randomSuffix string) string {
return fmt.Sprintf(`
data "google_project" "project" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,11 +1084,18 @@ workload_identity_config {

<a name="nested_node_pool_auto_config"></a>The `node_pool_auto_config` block supports:

* `node_kubelet_config` - (Optional) Kubelet configuration for Autopilot clusters. Currently, only `insecure_kubelet_readonly_port_enabled` is supported here.
Structure is [documented below](#nested_node_kubelet_config).

* `resource_manager_tags` - (Optional) A map of resource manager tag keys and values to be attached to the nodes for managing Compute Engine firewalls using Network Firewall Policies. Tags must be according to specifications found [here](https://cloud.google.com/vpc/docs/tags-firewalls-overview#specifications). A maximum of 5 tag key-value pairs can be specified. Existing tags will be replaced with new values. Tags must be in one of the following formats ([KEY]=[VALUE]) 1. `tagKeys/{tag_key_id}=tagValues/{tag_value_id}` 2. `{org_id}/{tag_key_name}={tag_value_name}` 3. `{project_id}/{tag_key_name}={tag_value_name}`.

* `network_tags` (Optional) - The network tag config for the cluster's automatically provisioned node pools.
* `network_tags` (Optional) - The network tag config for the cluster's automatically provisioned node pools. Structure is [documented below](#nested_network_tags).

<a name="nested_node_kubelet_config"></a>The `node_kubelet_config` block supports:

* `insecure_kubelet_readonly_port_enabled` - (Optional) Controls whether the kubelet read-only port is enabled. It is strongly recommended to set this to `FALSE`. Possible values: `TRUE`, `FALSE`.

The `network_tags` block supports:
<a name="nested_network_tags"></a>The `network_tags` block supports:

* `tags` (Optional) - List of network tags applied to auto-provisioned node pools.

Expand Down