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

"azurerm_kubernetes_cluster" and "azurerm_kubernetes_cluster_node_pool" supports "kubelet_config", "linux_os_config" #11119

Merged
merged 7 commits into from
Jun 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource {
}, false),
},

"kubelet_config": schemaNodePoolKubeletConfig(),

"linux_os_config": schemaNodePoolLinuxOSConfig(),

"max_count": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand Down Expand Up @@ -407,6 +411,21 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
return fmt.Errorf("`max_count` and `min_count` must be set to `null` when enable_auto_scaling is set to `false`")
}

if kubeletConfig := d.Get("kubelet_config").([]interface{}); len(kubeletConfig) > 0 {
profile.KubeletConfig = expandAgentPoolKubeletConfig(kubeletConfig)
}

if linuxOSConfig := d.Get("linux_os_config").([]interface{}); len(linuxOSConfig) > 0 {
if osType != string(containerservice.OSTypeLinux) {
return fmt.Errorf("`linux_os_config` can only be configured when `os_type` is set to `linux`")
}
linuxOSConfig, err := expandAgentPoolLinuxOSConfig(linuxOSConfig)
if err != nil {
return err
}
profile.LinuxOSConfig = linuxOSConfig
}

parameters := containerservice.AgentPool{
Name: &name,
ManagedClusterAgentPoolProfileProperties: &profile,
Expand Down Expand Up @@ -635,6 +654,18 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter
}
d.Set("eviction_policy", evictionPolicy)

if err := d.Set("kubelet_config", flattenAgentPoolKubeletConfig(props.KubeletConfig)); err != nil {
return fmt.Errorf("setting `kubelet_config`: %+v", err)
}

linuxOSConfig, err := flattenAgentPoolLinuxOSConfig(props.LinuxOSConfig)
if err != nil {
return err
}
if err := d.Set("linux_os_config", linuxOSConfig); err != nil {
return fmt.Errorf("setting `linux_os_config`: %+v", err)
}

maxCount := 0
if props.MaxCount != nil {
maxCount = int(*props.MaxCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var kubernetesNodePoolTests = map[string]func(t *testing.T){
"autoScaleUpdate": testAccKubernetesClusterNodePool_autoScaleUpdate,
"availabilityZones": testAccKubernetesClusterNodePool_availabilityZones,
"errorForAvailabilitySet": testAccKubernetesClusterNodePool_errorForAvailabilitySet,
"kubeletAndLinuxOSConfig": testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfig,
"kubeletAndLinuxOSConfigPartial": testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfigPartial,
"multiplePools": testAccKubernetesClusterNodePool_multiplePools,
"manualScale": testAccKubernetesClusterNodePool_manualScale,
"manualScaleMultiplePools": testAccKubernetesClusterNodePool_manualScaleMultiplePools,
Expand Down Expand Up @@ -161,6 +163,46 @@ func testAccKubernetesClusterNodePool_errorForAvailabilitySet(t *testing.T) {
})
}

func TestAccKubernetesClusterNodePool_kubeletAndLinuxOSConfig(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfig(t)
}

func testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfig(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.kubeletAndLinuxOSConfig(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesClusterNodePool_kubeletAndLinuxOSConfigPartial(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfigPartial(t)
}

func testAccKubernetesClusterNodePool_kubeletAndLinuxOSConfigPartial(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.kubeletAndLinuxOSConfigPartial(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesClusterNodePool_multiplePools(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccKubernetesClusterNodePool_multiplePools(t)
Expand Down Expand Up @@ -936,6 +978,147 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterNodePoolResource) kubeletAndLinuxOSConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}
}

resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_DS2_v2"
node_count = 1

kubelet_config {
cpu_manager_policy = "static"
cpu_cfs_quota_enabled = true
cpu_cfs_quota_period = "10ms"
image_gc_high_threshold = 90
image_gc_low_threshold = 70
topology_manager_policy = "best-effort"
allowed_unsafe_sysctls = ["kernel.msg*", "net.core.somaxconn"]
container_log_max_size_mb = 100
container_log_max_line = 100000
pod_max_pid = 12345
njuCZ marked this conversation as resolved.
Show resolved Hide resolved
}

linux_os_config {
transparent_huge_page_enabled = "always"
transparent_huge_page_defrag = "always"
swap_file_size_mb = 300

sysctl_config {
fs_aio_max_nr = 65536
fs_file_max = 100000
fs_inotify_max_user_watches = 1000000
fs_nr_open = 1048576
kernel_threads_max = 200000
net_core_netdev_max_backlog = 1800
net_core_optmem_max = 30000
net_core_rmem_max = 300000
net_core_rmem_default = 300000
net_core_somaxconn = 5000
net_core_wmem_default = 300000
net_core_wmem_max = 300000
net_ipv4_ip_local_port_range_min = 32768
net_ipv4_ip_local_port_range_max = 60000
net_ipv4_neigh_default_gc_thresh1 = 128
net_ipv4_neigh_default_gc_thresh2 = 512
net_ipv4_neigh_default_gc_thresh3 = 1024
net_ipv4_tcp_fin_timeout = 60
net_ipv4_tcp_keepalive_probes = 9
net_ipv4_tcp_keepalive_time = 6000
net_ipv4_tcp_max_syn_backlog = 2048
net_ipv4_tcp_max_tw_buckets = 100000
net_ipv4_tcp_tw_reuse = true
net_ipv4_tcp_keepalive_intvl = 70
net_netfilter_nf_conntrack_buckets = 65536
net_netfilter_nf_conntrack_max = 200000
vm_max_map_count = 65536
vm_swappiness = 45
vm_vfs_cache_pressure = 80
njuCZ marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterNodePoolResource) kubeletAndLinuxOSConfigPartial(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}
}

resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_DS2_v2"
node_count = 1

kubelet_config {
cpu_manager_policy = "static"
cpu_cfs_quota_enabled = true
cpu_cfs_quota_period = "10ms"
}

linux_os_config {
transparent_huge_page_enabled = "always"

sysctl_config {
fs_aio_max_nr = 65536
fs_file_max = 100000
fs_inotify_max_user_watches = 1000000
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterNodePoolResource) availabilityZonesConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down