Skip to content

Commit 77bda19

Browse files
fix(container_node_pool): panic interface conversion on linux_node_config.sysctls (#8981) (#15941)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Shuya Ma <[email protected]>
1 parent ff63d88 commit 77bda19

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

.changelog/8981.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed an issue in `google_container_node_pool` where empty `linux_node_config.sysctls` would crash the provider
3+
```

google/services/container/node_config.go

+3
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,9 @@ func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig {
924924
if len(ls) == 0 {
925925
return nil
926926
}
927+
if ls[0] == nil {
928+
return &container.LinuxNodeConfig{}
929+
}
927930
cfg := ls[0].(map[string]interface{})
928931
sysCfgRaw, ok := cfg["sysctls"]
929932
if !ok {

google/services/container/resource_container_node_pool_test.go

+37-17
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,17 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) {
411411
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
412412
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
413413
Steps: []resource.TestStep{
414+
// Create a node pool with empty `linux_node_config.sysctls`.
414415
{
415-
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, 10000, 12800, "1000 20000 100000", 1),
416+
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, ""),
417+
},
418+
{
419+
ResourceName: "google_container_node_pool.with_linux_node_config",
420+
ImportState: true,
421+
ImportStateVerify: true,
422+
},
423+
{
424+
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 100000"),
416425
},
417426
{
418427
ResourceName: "google_container_node_pool.with_linux_node_config",
@@ -421,7 +430,7 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) {
421430
},
422431
// Perform an update.
423432
{
424-
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, 10000, 12800, "1000 20000 200000", 1),
433+
Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 200000"),
425434
},
426435
{
427436
ResourceName: "google_container_node_pool.with_linux_node_config",
@@ -2353,7 +2362,30 @@ resource "google_container_node_pool" "with_kubelet_config" {
23532362
`, cluster, np, policy, quota, period, podPidsLimit)
23542363
}
23552364

2356-
func testAccContainerNodePool_withLinuxNodeConfig(cluster, np string, maxBacklog, soMaxConn int, tcpMem string, twReuse int) string {
2365+
func testAccContainerNodePool_withLinuxNodeConfig(cluster, np string, tcpMem string) string {
2366+
linuxNodeConfig := `
2367+
linux_node_config {
2368+
sysctls = {}
2369+
}
2370+
`
2371+
if len(tcpMem) != 0 {
2372+
linuxNodeConfig = fmt.Sprintf(`
2373+
linux_node_config {
2374+
sysctls = {
2375+
"net.core.netdev_max_backlog" = "10000"
2376+
"net.core.rmem_max" = 10000
2377+
"net.core.wmem_default" = 10000
2378+
"net.core.wmem_max" = 20000
2379+
"net.core.optmem_max" = 10000
2380+
"net.core.somaxconn" = 12800
2381+
"net.ipv4.tcp_rmem" = "%s"
2382+
"net.ipv4.tcp_wmem" = "%s"
2383+
"net.ipv4.tcp_tw_reuse" = 1
2384+
}
2385+
}
2386+
`, tcpMem, tcpMem)
2387+
}
2388+
23572389
return fmt.Sprintf(`
23582390
data "google_container_engine_versions" "central1a" {
23592391
location = "us-central1-a"
@@ -2373,26 +2405,14 @@ resource "google_container_node_pool" "with_linux_node_config" {
23732405
initial_node_count = 1
23742406
node_config {
23752407
image_type = "COS_CONTAINERD"
2376-
linux_node_config {
2377-
sysctls = {
2378-
"net.core.netdev_max_backlog" = "%d"
2379-
"net.core.rmem_max" = 10000
2380-
"net.core.wmem_default" = 10000
2381-
"net.core.wmem_max" = 20000
2382-
"net.core.optmem_max" = 10000
2383-
"net.core.somaxconn" = %d
2384-
"net.ipv4.tcp_rmem" = "%s"
2385-
"net.ipv4.tcp_wmem" = "%s"
2386-
"net.ipv4.tcp_tw_reuse" = %d
2387-
}
2388-
}
2408+
%s
23892409
oauth_scopes = [
23902410
"https://www.googleapis.com/auth/logging.write",
23912411
"https://www.googleapis.com/auth/monitoring",
23922412
]
23932413
}
23942414
}
2395-
`, cluster, np, maxBacklog, soMaxConn, tcpMem, tcpMem, twReuse)
2415+
`, cluster, np, linuxNodeConfig)
23962416
}
23972417

23982418
func testAccContainerNodePool_withNetworkConfig(cluster, np, network string) string {

0 commit comments

Comments
 (0)