Skip to content

Commit

Permalink
fix(container_node_pool): panic interface conversion on `linux_node_c…
Browse files Browse the repository at this point in the history
…onfig.sysctls` (#8981) (hashicorp#6339)

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Shuya Ma <[email protected]>
  • Loading branch information
modular-magician and shuyama1 authored Sep 22, 2023
1 parent 0796e08 commit 4d1937a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .changelog/8981.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: fixed an issue in `google_container_node_pool` where empty `linux_node_config.sysctls` would crash the provider
```
3 changes: 3 additions & 0 deletions google-beta/services/container/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,9 @@ func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig {
if len(ls) == 0 {
return nil
}
if ls[0] == nil {
return &container.LinuxNodeConfig{}
}
cfg := ls[0].(map[string]interface{})
sysCfgRaw, ok := cfg["sysctls"]
if !ok {
Expand Down
54 changes: 37 additions & 17 deletions google-beta/services/container/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,17 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) {
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
// Create a node pool with empty `linux_node_config.sysctls`.
{
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, 10000, 12800, "1000 20000 100000", 1),
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, ""),
},
{
ResourceName: "google_container_node_pool.with_linux_node_config",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 100000"),
},
{
ResourceName: "google_container_node_pool.with_linux_node_config",
Expand All @@ -474,7 +483,7 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) {
},
// Perform an update.
{
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, 10000, 12800, "1000 20000 200000", 1),
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 200000"),
},
{
ResourceName: "google_container_node_pool.with_linux_node_config",
Expand Down Expand Up @@ -2604,7 +2613,30 @@ resource "google_container_node_pool" "with_kubelet_config" {
`, cluster, np, policy, quota, period, podPidsLimit)
}

func testAccContainerNodePool_withLinuxNodeConfig(cluster, np string, maxBacklog, soMaxConn int, tcpMem string, twReuse int) string {
func testAccContainerNodePool_withLinuxNodeConfig(cluster, np string, tcpMem string) string {
linuxNodeConfig := `
linux_node_config {
sysctls = {}
}
`
if len(tcpMem) != 0 {
linuxNodeConfig = fmt.Sprintf(`
linux_node_config {
sysctls = {
"net.core.netdev_max_backlog" = "10000"
"net.core.rmem_max" = 10000
"net.core.wmem_default" = 10000
"net.core.wmem_max" = 20000
"net.core.optmem_max" = 10000
"net.core.somaxconn" = 12800
"net.ipv4.tcp_rmem" = "%s"
"net.ipv4.tcp_wmem" = "%s"
"net.ipv4.tcp_tw_reuse" = 1
}
}
`, tcpMem, tcpMem)
}

return fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
location = "us-central1-a"
Expand All @@ -2624,26 +2656,14 @@ resource "google_container_node_pool" "with_linux_node_config" {
initial_node_count = 1
node_config {
image_type = "COS_CONTAINERD"
linux_node_config {
sysctls = {
"net.core.netdev_max_backlog" = "%d"
"net.core.rmem_max" = 10000
"net.core.wmem_default" = 10000
"net.core.wmem_max" = 20000
"net.core.optmem_max" = 10000
"net.core.somaxconn" = %d
"net.ipv4.tcp_rmem" = "%s"
"net.ipv4.tcp_wmem" = "%s"
"net.ipv4.tcp_tw_reuse" = %d
}
}
%s
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
}
}
`, cluster, np, maxBacklog, soMaxConn, tcpMem, tcpMem, twReuse)
`, cluster, np, linuxNodeConfig)
}

func testAccContainerNodePool_withNetworkConfig(cluster, np, network string) string {
Expand Down

0 comments on commit 4d1937a

Please sign in to comment.