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 support for enable_relay field to advanced_datapath_observability_config #17262

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
4 changes: 4 additions & 0 deletions .changelog/9633.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
container: added support for `enable_relay` field to `advanced_datapath_observability_config`
container: deprecated support for `relay_mode` field in `advanced_datapath_observability_config` in favor of `enable_relay` field, `relay_mode` field will be removed in upcoming releases
```
59 changes: 51 additions & 8 deletions google/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ func ResourceContainerCluster() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 2,
MaxItems: 1,
Description: `Configuration of Advanced Datapath Observability features.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -1062,12 +1062,21 @@ func ResourceContainerCluster() *schema.Resource {
Required: true,
Description: `Whether or not the advanced datapath metrics are enabled.`,
},
"enable_relay": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether or not Relay is enabled.`,
Default: false,
ConflictsWith: []string{"monitoring_config.0.advanced_datapath_observability_config.0.relay_mode"},
},
"relay_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Mode used to make Relay available.`,
ValidateFunc: validation.StringInSlice([]string{"DISABLED", "INTERNAL_VPC_LB", "EXTERNAL_LB"}, false),
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "Deprecated in favor of enable_relay field. Remove this attribute's configuration as this field will be removed in the next major release and enable_relay will become a required field.",
Description: `Mode used to make Relay available.`,
ValidateFunc: validation.StringInSlice([]string{"DISABLED", "INTERNAL_VPC_LB", "EXTERNAL_LB"}, false),
ConflictsWith: []string{"monitoring_config.0.advanced_datapath_observability_config.0.enable_relay"},
},
},
},
Expand Down Expand Up @@ -4808,7 +4817,18 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig

mc.AdvancedDatapathObservabilityConfig = &container.AdvancedDatapathObservabilityConfig{
EnableMetrics: advanced_datapath_observability_config["enable_metrics"].(bool),
RelayMode: advanced_datapath_observability_config["relay_mode"].(string),
}

enable_relay := advanced_datapath_observability_config["enable_relay"].(bool)
relay_mode := advanced_datapath_observability_config["relay_mode"].(string)
if enable_relay {
mc.AdvancedDatapathObservabilityConfig.EnableRelay = enable_relay
} else if relay_mode == "INTERNAL_VPC_LB" || relay_mode == "EXTERNAL_LB" {
mc.AdvancedDatapathObservabilityConfig.RelayMode = relay_mode
} else {
mc.AdvancedDatapathObservabilityConfig.EnableRelay = enable_relay
mc.AdvancedDatapathObservabilityConfig.RelayMode = "DISABLED"
mc.AdvancedDatapathObservabilityConfig.ForceSendFields = []string{"EnableRelay"}
}
}

Expand Down Expand Up @@ -5555,10 +5575,33 @@ func flattenMonitoringConfig(c *container.MonitoringConfig) []map[string]interfa
}

func flattenAdvancedDatapathObservabilityConfig(c *container.AdvancedDatapathObservabilityConfig) []map[string]interface{} {
if c == nil {
return nil
}

if c.EnableRelay {
return []map[string]interface{}{
{
"enable_metrics": c.EnableMetrics,
"enable_relay": c.EnableRelay,
},
}
}

if c.RelayMode == "INTERNAL_VPC_LB" || c.RelayMode == "EXTERNAL_LB" {
return []map[string]interface{}{
{
"enable_metrics": c.EnableMetrics,
"relay_mode": c.RelayMode,
},
}
}

return []map[string]interface{}{
{
"enable_metrics": c.EnableMetrics,
"relay_mode": c.RelayMode,
"enable_relay": false,
"relay_mode": "DISABLED",
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ func resourceContainerClusterResourceV1() *schema.Resource {
Required: true,
Description: `Whether or not the advanced datapath metrics are enabled.`,
},
"enable_relay": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether or not Relay is enabled.`,
},
"relay_mode": {
Type: schema.TypeString,
Optional: true,
Expand Down
118 changes: 118 additions & 0 deletions google/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,24 @@ func TestAccContainerCluster_withMonitoringConfigAdvancedDatapathObservabilityCo
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
{
Config: testAccContainerCluster_withMonitoringConfigAdvancedDatapathObservabilityConfigEnabledOld(clusterName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
{
Config: testAccContainerCluster_withMonitoringConfigAdvancedDatapathObservabilityConfigDisabledOld(clusterName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
},
})
}
Expand Down Expand Up @@ -7797,6 +7815,56 @@ resource "google_compute_subnetwork" "container_subnetwork" {
}
}

resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
datapath_provider = "ADVANCED_DATAPATH"

network = google_compute_network.container_network.name
subnetwork = google_compute_subnetwork.container_subnetwork.name
ip_allocation_policy {
cluster_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[0].range_name
services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
}

monitoring_config {
enable_components = []
advanced_datapath_observability_config {
enable_metrics = true
enable_relay = true
}
}
deletion_protection = false
}
`, name, name)
}

func testAccContainerCluster_withMonitoringConfigAdvancedDatapathObservabilityConfigEnabledOld(name string) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
name = "%s-nw"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "container_subnetwork" {
name = google_compute_network.container_network.name
network = google_compute_network.container_network.name
ip_cidr_range = "10.0.36.0/24"
region = "us-central1"
private_ip_google_access = true

secondary_ip_range {
range_name = "services-range"
ip_cidr_range = "192.168.1.0/24"
}

secondary_ip_range {
range_name = "pod-ranges"
ip_cidr_range = "192.168.64.0/22"
}
}

resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
Expand Down Expand Up @@ -7847,6 +7915,56 @@ resource "google_compute_subnetwork" "container_subnetwork" {
}
}

resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
datapath_provider = "ADVANCED_DATAPATH"

network = google_compute_network.container_network.name
subnetwork = google_compute_subnetwork.container_subnetwork.name
ip_allocation_policy {
cluster_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[0].range_name
services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
}

monitoring_config {
enable_components = []
advanced_datapath_observability_config {
enable_metrics = false
enable_relay = false
}
}
deletion_protection = false
}
`, name, name)
}

func testAccContainerCluster_withMonitoringConfigAdvancedDatapathObservabilityConfigDisabledOld(name string) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
name = "%s-nw"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "container_subnetwork" {
name = google_compute_network.container_network.name
network = google_compute_network.container_network.name
ip_cidr_range = "10.0.36.0/24"
region = "us-central1"
private_ip_google_access = true

secondary_ip_range {
range_name = "services-range"
ip_cidr_range = "192.168.1.0/24"
}

secondary_ip_range {
range_name = "pod-ranges"
ip_cidr_range = "192.168.64.0/22"
}
}

resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ This block also contains several computed attributes, documented below.
<a name="nested_advanced_datapath_observability_config"></a>The `advanced_datapath_observability_config` block supports:

* `enable_metrics` - (Required) Whether or not to enable advanced datapath metrics.
* `enable_relay` - (Optional) Whether or not Relay is enabled.
* `relay_mode` - (Optional) Mode used to make Relay available.

<a name="nested_maintenance_policy"></a>The `maintenance_policy` block supports:
Expand Down
Loading