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

GKE L4 ILB Subsetting support #4626

Merged
merged 19 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
71c3aeb
Merge pull request #1 from GoogleCloudPlatform/master
upodroid Aug 3, 2020
e1a9488
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Aug 10, 2020
51eaff6
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Aug 25, 2020
649e97c
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Sep 21, 2020
ee373cc
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Oct 3, 2020
d330773
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Oct 27, 2020
0d73e9f
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Nov 17, 2020
191a775
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Dec 15, 2020
b90d594
mark field as updatable
upodroid Jan 5, 2021
4b79149
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Jan 20, 2021
a3e1989
Merge branch 'master' of github.com:borg-land/magic-modules
upodroid Jan 26, 2021
9ffeb0b
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Jan 26, 2021
9dd54f3
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Feb 1, 2021
b917f22
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Feb 15, 2021
7b836a0
Merge branch 'master' of github.com:GoogleCloudPlatform/magic-modules
upodroid Mar 22, 2021
5e341dc
add l4 subsetting support
upodroid Mar 25, 2021
34ec203
fix beta guarding
upodroid Mar 29, 2021
0a0326c
fix change typo
upodroid Mar 29, 2021
89a69b0
add more beta guards
upodroid Mar 29, 2021
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
114 changes: 114 additions & 0 deletions mmv1/third_party/terraform/resources/resource_container_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ func rfc5545RecurrenceDiffSuppress(k, o, n string, d *schema.ResourceData) bool
return false
}

<% unless version == 'ga' -%>
// Has enable_l4_ilb_subsetting been enabled before?
func isBeenEnabled(_ context.Context, old, new, _ interface{}) bool {
if old == nil || new == nil {
return false
}

// if subsetting is enabled, but is not now
if old.(bool) && !new.(bool) {
return true
}

return false
}
<% end -%>

func resourceContainerCluster() *schema.Resource {
return &schema.Resource{
UseJSONNumber: true,
Expand All @@ -109,6 +125,9 @@ func resourceContainerCluster() *schema.Resource {
CustomizeDiff: customdiff.All(
resourceNodeConfigEmptyGuestAccelerator,
containerClusterPrivateClusterConfigCustomDiff,
<% unless version == 'ga' -%>
customdiff.ForceNewIfChange("enable_l4_ilb_subsetting", isBeenEnabled),
upodroid marked this conversation as resolved.
Show resolved Hide resolved
<% end -%>
),

Timeouts: &schema.ResourceTimeout{
Expand Down Expand Up @@ -1175,6 +1194,20 @@ func resourceContainerCluster() *schema.Resource {
Default: false,
<% end -%>
},
<% unless version == 'ga' -%>
"enable_l4_ilb_subsetting": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether L4ILB Subsetting is enabled for this cluster.`,
Default: false,
},
<% end -%>
"private_ipv6_google_access": {
Type: schema.TypeString,
Optional: true,
Description: `The desired state of IPv6 connectivity to Google Services. By default, no private IPv6 access to or from Google Services (all access will be via IPv4).`,
Computed: true,
},

"resource_usage_export_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1342,6 +1375,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
EnableIntraNodeVisibility: d.Get("enable_intranode_visibility").(bool),
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
DatapathProvider: d.Get("datapath_provider").(string),
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
<% unless version == 'ga' -%>
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
<% end -%>
},
MasterAuth: expandMasterAuth(d.Get("master_auth")),
<% unless version == 'ga' -%>
Expand Down Expand Up @@ -1677,6 +1714,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("confidential_nodes", flattenConfidentialNodes(cluster.ConfidentialNodes)); err != nil {
return err
}
if err := d.Set("enable_l4_ilb_subsetting", cluster.NetworkConfig.EnableL4ilbSubsetting); err != nil {
return fmt.Errorf("Error setting enable_l4_ilb_subsetting: %s", err)
}
<% end -%>
if err := d.Set("enable_tpu", cluster.EnableTpu); err != nil {
return fmt.Errorf("Error setting enable_tpu: %s", err)
Expand All @@ -1693,6 +1733,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("enable_intranode_visibility", cluster.NetworkConfig.EnableIntraNodeVisibility); err != nil {
return fmt.Errorf("Error setting enable_intranode_visibility: %s", err)
}
if err := d.Set("private_ipv6_google_access", cluster.NetworkConfig.PrivateIpv6GoogleAccess); err != nil {
return fmt.Errorf("Error setting private_ipv6_google_access: %s", err)
}
if err := d.Set("authenticator_groups_config", flattenAuthenticatorGroupsConfig(cluster.AuthenticatorGroupsConfig)); err != nil {
return err
}
Expand Down Expand Up @@ -1977,6 +2020,77 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s Intra Node Visibility has been updated to %v", d.Id(), enabled)
}

if d.HasChange("private_ipv6_google_access") {
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
DesiredPrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
},
}
updateF := func() error {
log.Println("[DEBUG] updating private_ipv6_google_access")
name := containerClusterFullName(project, location, clusterName)
clusterUpdateCall := config.NewContainerBetaClient(userAgent).Projects.Locations.Clusters.Update(name, req)
if config.UserProjectOverride {
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
}
op, err := clusterUpdateCall.Do()
if err != nil {
return err
}

// Wait until it's updated
err = containerOperationWait(config, op, project, location, "updating GKE Private IPv6 Google Access", userAgent, d.Timeout(schema.TimeoutUpdate))
log.Println("[DEBUG] done updating private_ipv6_google_access")
return err
}

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

log.Printf("[INFO] GKE cluster %s Private IPv6 Google Access has been updated", d.Id())
}

<% unless version == 'ga' -%>
if d.HasChange("enable_l4_ilb_subsetting") {
upodroid marked this conversation as resolved.
Show resolved Hide resolved
// This field can be changed from false to true but not from false to true. CustomizeDiff handles that check.
enabled := d.Get("enable_l4_ilb_subsetting").(bool)
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
DesiredL4ilbSubsettingConfig: &containerBeta.ILBSubsettingConfig{
Enabled: enabled,
ForceSendFields: []string{"Enabled"},
},
},
}
updateF := func() error {
log.Println("[DEBUG] updating enable_l4_ilb_subsetting")
name := containerClusterFullName(project, location, clusterName)
clusterUpdateCall := config.NewContainerBetaClient(userAgent).Projects.Locations.Clusters.Update(name, req)
if config.UserProjectOverride {
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
}
op, err := clusterUpdateCall.Do()
if err != nil {
return err
}

// Wait until it's updated
err = containerOperationWait(config, op, project, location, "updating L4", userAgent, d.Timeout(schema.TimeoutUpdate))
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 L4 ILB Subsetting has been updated to %v", d.Id(), enabled)
}
<% end -%>

if d.HasChange("default_snat_status") {
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,47 @@ func TestAccContainerCluster_withConfidentialNodes(t *testing.T) {
}
<% end -%>

<% unless version == 'ga' -%>
func TestAccContainerCluster_withILBSubsetting(t *testing.T) {
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
npName := fmt.Sprintf("tf-test-cluster-nodepool-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_disableILBSubSetting(clusterName, npName),
},
{
ResourceName: "google_container_cluster.confidential_nodes",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withILBSubSetting(clusterName, npName),
},
{
ResourceName: "google_container_cluster.confidential_nodes",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_disableILBSubSetting(clusterName, npName),
},
{
ResourceName: "google_container_cluster.confidential_nodes",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
<% end -%>

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

Expand Down Expand Up @@ -2516,6 +2557,54 @@ resource "google_container_cluster" "confidential_nodes" {
}
<% end -%>

<% unless version == 'ga' -%>
func testAccContainerCluster_withILBSubSetting(clusterName string, npName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "confidential_nodes" {
name = "%s"
location = "us-central1-a"
enable_shielded_nodes = true
release_channel {
channel = "RAPID"
}

node_pool {
name = "%s"
initial_node_count = 1
node_config {
machine_type = "n2d-standard-2"
}
}

enable_l4_ilb_subsetting = true
}
`, clusterName, npName)
}

func testAccContainerCluster_disableILBSubSetting(clusterName string, npName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "confidential_nodes" {
name = "%s"
location = "us-central1-a"
enable_shielded_nodes = true
release_channel {
channel = "RAPID"
}

node_pool {
name = "%s"
initial_node_count = 1
node_config {
machine_type = "n2d-standard-2"
}
}

enable_l4_ilb_subsetting = false
}
`, clusterName, npName)
}
<% end -%>

func testAccContainerCluster_withMasterAuth(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_master_auth" {
Expand Down Expand Up @@ -2896,7 +2985,7 @@ resource "google_container_cluster" "with_intranode_visibility" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
enable_intranode_visibility = true
enable_intranode_visibility = true
}
`, clusterName)
}
Expand All @@ -2908,6 +2997,7 @@ resource "google_container_cluster" "with_intranode_visibility" {
location = "us-central1-a"
initial_node_count = 1
enable_intranode_visibility = false
private_ipv6_google_access = "PRIVATE_IPV6_GOOGLE_ACCESS_BIDIRECTIONAL"
}
`, clusterName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ subnetwork in which the cluster's instances are launched.
* `enable_intranode_visibility` - (Optional)
Whether Intra-node visibility is enabled for this cluster. This makes same node pod to pod traffic visible for VPC network.

* `enable_l4_ilb_subsetting` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Whether L4ILB Subsetting is enabled for this cluster.

* `private_ipv6_google_access` - (Optional)
The desired state of IPv6 connectivity to Google Services. By default, no private IPv6 access to or from Google Services (all access will be via IPv4).

* `datapath_provider` - (Optional)
The desired datapath provider for this cluster. By default, uses the IPTables-based kube-proxy implementation.

Expand Down