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

add cilium clusterwide network policies support #10225

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,12 @@ func ResourceContainerCluster() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"DATAPATH_PROVIDER_UNSPECIFIED", "LEGACY_DATAPATH", "ADVANCED_DATAPATH"}, false),
DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("DATAPATH_PROVIDER_UNSPECIFIED"),
},

"enable_cilium_clusterwide_network_policy": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether Cilium cluster-wide network policy is enabled on this cluster.`,
Default: false,
},
"enable_intranode_visibility": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -2252,13 +2257,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
<% end -%>
EnableTpu: d.Get("enable_tpu").(bool),
NetworkConfig: &container.NetworkConfig{
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),
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
DnsConfig: expandDnsConfig(d.Get("dns_config")),
GatewayApiConfig: expandGatewayApiConfig(d.Get("gateway_api_config")),
EnableIntraNodeVisibility: d.Get("enable_intranode_visibility").(bool),
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
DatapathProvider: d.Get("datapath_provider").(string),
EnableCiliumClusterwideNetworkPolicy: d.Get("enable_cilium_clusterwide_network_policy").(bool),
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
DnsConfig: expandDnsConfig(d.Get("dns_config")),
GatewayApiConfig: expandGatewayApiConfig(d.Get("gateway_api_config")),
<% unless version == "ga" -%>
EnableMultiNetworking: d.Get("enable_multi_networking").(bool),
EnableFqdnNetworkPolicy: d.Get("enable_fqdn_network_policy").(bool),
Expand Down Expand Up @@ -2790,6 +2796,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("datapath_provider", cluster.NetworkConfig.DatapathProvider); err != nil {
return fmt.Errorf("Error setting datapath_provider: %s", err)
}
if err := d.Set("enable_cilium_clusterwide_network_policy", cluster.NetworkConfig.EnableCiliumClusterwideNetworkPolicy); err != nil {
return fmt.Errorf("Error setting enable_cilium_clusterwide_network_policy: %s", err)
}
if err := d.Set("default_snat_status", flattenDefaultSnatStatus(cluster.NetworkConfig.DefaultSnatStatus)); err != nil {
return err
}
Expand Down Expand Up @@ -3293,6 +3302,22 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
<% end -%>

if d.HasChange("enable_cilium_clusterwide_network_policy") {
enabled := d.Get("enable_cilium_clusterwide_network_policy").(bool)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
desiredEnableCiliumClusterwideNetworkPolicy: enabled,
},
}
updateF := updateFunc(req, "updating cilium clusterwide network policy")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s Cilium Clusterwide Network Policy has been updated to %v", d.Id(), enabled)
}

if d.HasChange("cost_management_config") {
c := d.Get("cost_management_config")
req := &container.UpdateClusterRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To get more information about GKE clusters, see:
* [About cluster configuration choices](https://cloud.google.com/kubernetes-engine/docs/concepts/types-of-clusters)
* Terraform guidance
* [Using GKE with Terraform](/docs/providers/google/guides/using_gke_with_terraform.html)
* [Provision a GKE Cluster (Google Cloud) Learn tutorial](https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS)
* [Provision a GKE Cluster (Google Cloud) Learn tutorial](https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS)

-> On version 5.0.0+ of the provider, you must explicitly set `deletion_protection = false`
and run `terraform apply` to write the field to state in order to destroy a cluster.
Expand Down Expand Up @@ -364,6 +364,9 @@ subnetwork in which the cluster's instances are launched.
* `datapath_provider` - (Optional)
The desired datapath provider for this cluster. This is set to `LEGACY_DATAPATH` by default, which uses the IPTables-based kube-proxy implementation. Set to `ADVANCED_DATAPATH` to enable Dataplane v2.

* `enable_cilium_clusterwide_network_policy` - (Optional)
Whether CiliumClusterWideNetworkPolicy is enabled on this cluster. Defaults to false.

* `default_snat_status` - (Optional)
[GKE SNAT](https://cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent#how_ipmasq_works) DefaultSnatStatus contains the desired state of whether default sNAT should be disabled on the cluster, [API doc](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#networkconfig). Structure is [documented below](#nested_default_snat_status)

Expand Down