Skip to content

Commit

Permalink
Support for GKE intranode visibility
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
chrisst authored and modular-magician committed Jun 4, 2019
1 parent 01a5d63 commit c6800c1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ENHANCEMENTS:

BUG FIXES:
* compute: `google_project_iam` When importing resources `project` no longer needs to be set in the config post import [GH-805]
* compute: `google_sql_user` User's can now be updated to change their password [GH-810]

## 2.8.0 (June 04, 2019)

Expand Down
46 changes: 45 additions & 1 deletion google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ func resourceContainerCluster() *schema.Resource {
},
},
},

"enable_intranode_visibility": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -807,7 +813,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
Enabled: d.Get("enable_binary_authorization").(bool),
ForceSendFields: []string{"Enabled"},
},
Autoscaling: expandClusterAutoscaling(d.Get("cluster_autoscaling"), d),
Autoscaling: expandClusterAutoscaling(d.Get("cluster_autoscaling"), d),
NetworkConfig: &containerBeta.NetworkConfig{
EnableIntraNodeVisibility: d.Get("enable_intranode_visibility").(bool),
},
MasterAuth: expandMasterAuth(d.Get("master_auth")),
ResourceLabels: expandStringMap(d, "resource_labels"),
}
Expand Down Expand Up @@ -1049,6 +1058,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("authenticator_groups_config", flattenAuthenticatorGroupsConfig(cluster.AuthenticatorGroupsConfig)); err != nil {
return err
}
d.Set("enable_intranode_visibility", cluster.NetworkConfig.EnableIntraNodeVisibility)
if err := d.Set("node_config", flattenNodeConfig(cluster.NodeConfig)); err != nil {
return err
}
Expand Down Expand Up @@ -1206,6 +1216,40 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
d.SetPartial("cluster_autoscaling")
}

if d.HasChange("enable_intranode_visibility") {
enabled := d.Get("enable_intranode_visibility").(bool)
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
DesiredIntraNodeVisibilityConfig: &containerBeta.IntraNodeVisibilityConfig{
Enabled: enabled,
ForceSendFields: []string{"Enabled"},
},
},
}
updateF := func() error {
log.Println("[DEBUG] updating enable_intranode_visibility")
name := containerClusterFullName(project, location, clusterName)
op, err := config.clientContainerBeta.Projects.Locations.Clusters.Update(name, req).Do()
if err != nil {
return err
}

// Wait until it's updated
err = containerOperationWait(config, op, project, location, "updating GKE Intra Node Visibility", timeoutInMinutes)
log.Println("[DEBUG] done updating enable_intranode_visibility")
return err
}

// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s Intra Node Visibility has been updated to %v", d.Id(), enabled)

d.SetPartial("enable_intranode_visibility")
}

if d.HasChange("maintenance_policy") {
var req *containerBeta.SetMaintenancePolicyRequest
if mp, ok := d.GetOk("maintenance_policy"); ok {
Expand Down
58 changes: 58 additions & 0 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,44 @@ func TestAccContainerCluster_withLegacyAbac(t *testing.T) {
})
}

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

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withIntraNodeVisibility(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.with_intranode_visibility", "enable_intranode_visibility", "true"),
),
},
{
ResourceName: "google_container_cluster.with_intranode_visibility",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_updateIntraNodeVisibility(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.with_intranode_visibility", "enable_intranode_visibility", "false"),
),
},
{
ResourceName: "google_container_cluster.with_intranode_visibility",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

/*
Since GKE disables legacy ABAC by default in Kubernetes version 1.8+, and the default Kubernetes
version for GKE is also 1.8+, this test will ensure that legacy ABAC is disabled by default to be
Expand Down Expand Up @@ -2367,6 +2405,26 @@ resource "google_container_cluster" "with_legacy_abac" {
}`, clusterName)
}

func testAccContainerCluster_withIntraNodeVisibility(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_intranode_visibility" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 1
enable_intranode_visibility = true
}`, clusterName)
}

func testAccContainerCluster_updateIntraNodeVisibility(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_intranode_visibility" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 1
enable_intranode_visibility = false
}`, clusterName)
}

func testAccContainerCluster_withVersion(clusterName string) string {
return fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,13 @@ to the datasource. A `region` can have a different set of supported versions tha
* `subnetwork` - (Optional) The name or self_link of the Google Compute Engine subnetwork in
which the cluster's instances are launched.

* `vertical_pod_autoscaling` - Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it.
* `vertical_pod_autoscaling` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html))
Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it.
Structure is documented below.

* `enable_intranode_visibility` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html))
Whether Intra-node visibility is enabled for this cluster. This makes same node pod to pod traffic visible for VPC network.

The `addons_config` block supports:

* `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod Autoscaling
Expand Down

0 comments on commit c6800c1

Please sign in to comment.