Skip to content

Commit deef485

Browse files
committed
2 parents aeb118b + 634d0a5 commit deef485

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

mmv1/third_party/tgc_next/pkg/services/container/node_config.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,36 @@ func schemaNodeConfig() *schema.Schema {
10271027
},
10281028
},
10291029
},
1030+
"swap_config": {
1031+
Type: schema.TypeList,
1032+
Optional: true,
1033+
MaxItems: 1,
1034+
Description: `Parameters that can be configured on Linux nodes.`,
1035+
Elem: &schema.Resource{
1036+
Schema: map[string]*schema.Schema{
1037+
"enabled": {
1038+
Type: schema.TypeBool,
1039+
Optional: true,
1040+
Description: `Whether or not swap is enabled`,
1041+
},
1042+
"boot_disk_profile": {
1043+
Type: schema.TypeList,
1044+
Optional: true,
1045+
MaxItems: 1,
1046+
Description: `Swap disk profile for boot disk`,
1047+
Elem: &schema.Resource{
1048+
Schema: map[string]*schema.Schema{
1049+
"swap_size_gib": {
1050+
Type: schema.TypeInt,
1051+
Optional: true,
1052+
Description: `Swap size in GiB`,
1053+
},
1054+
},
1055+
},
1056+
},
1057+
},
1058+
},
1059+
},
10301060
},
10311061
},
10321062
},
@@ -1967,9 +1997,56 @@ func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig {
19671997
linuxNodeConfig.NodeKernelModuleLoading = expandNodeKernelModuleLoading(v)
19681998
}
19691999

2000+
if v, ok := cfg["swap_config"]; ok {
2001+
linuxNodeConfig.SwapConfig = expandSwapConfig(v)
2002+
}
2003+
19702004
return linuxNodeConfig
19712005
}
19722006

2007+
func expandSwapConfig(v interface{}) *container.SwapConfig {
2008+
if v == nil {
2009+
return nil
2010+
}
2011+
ls := v.([]interface{})
2012+
if len(ls) == 0 {
2013+
return nil
2014+
}
2015+
if ls[0] == nil {
2016+
return &container.SwapConfig{}
2017+
}
2018+
cfg := ls[0].(map[string]interface{})
2019+
2020+
swapConfig := &container.SwapConfig{}
2021+
if v, ok := cfg["enabled"]; ok {
2022+
swapConfig.Enabled = v.(bool)
2023+
}
2024+
if v, ok := cfg["boot_disk_profile"]; ok {
2025+
swapConfig.BootDiskProfile = expandBootDiskProfile(v)
2026+
}
2027+
return swapConfig
2028+
}
2029+
2030+
func expandBootDiskProfile(v interface{}) *container.BootDiskProfile {
2031+
if v == nil {
2032+
return nil
2033+
}
2034+
ls := v.([]interface{})
2035+
if len(ls) == 0 {
2036+
return nil
2037+
}
2038+
if ls[0] == nil {
2039+
return &container.BootDiskProfile{}
2040+
}
2041+
cfg := ls[0].(map[string]interface{})
2042+
2043+
bdp := &container.BootDiskProfile{}
2044+
if v, ok := cfg["swap_size_gib"]; ok {
2045+
bdp.SwapSizeGib = int64(v.(int))
2046+
}
2047+
return bdp
2048+
}
2049+
19732050
func expandWindowsNodeConfig(v interface{}) *container.WindowsNodeConfig {
19742051
if v == nil {
19752052
return nil
@@ -3016,11 +3093,33 @@ func flattenLinuxNodeConfig(v interface{}) []map[string]interface{} {
30163093
"transparent_hugepage_enabled": c["transparentHugepageEnabled"],
30173094
"transparent_hugepage_defrag": c["transparentHugepageDefrag"],
30183095
"node_kernel_module_loading": flattenNodeKernelModuleLoading(c["nodeKernelModuleLoading"]),
3096+
"swap_config": flattenSwapConfig(c["swapConfig"]),
30193097
}
30203098

30213099
return []map[string]interface{}{transformed}
30223100
}
30233101

3102+
func flattenSwapConfig(v interface{}) []map[string]interface{} {
3103+
if v == nil {
3104+
return nil
3105+
}
3106+
c, ok := v.(map[string]interface{})
3107+
if !ok {
3108+
return nil
3109+
}
3110+
transformed := map[string]interface{}{
3111+
"enabled": c["enabled"],
3112+
}
3113+
if bdp, ok := c["bootDiskProfile"].(map[string]interface{}); ok {
3114+
transformed["boot_disk_profile"] = []map[string]interface{}{
3115+
{
3116+
"swap_size_gib": bdp["swapSizeGib"],
3117+
},
3118+
}
3119+
}
3120+
return []map[string]interface{}{transformed}
3121+
}
3122+
30243123
func flattenWindowsNodeConfig(v interface{}) []map[string]interface{} {
30253124
if v == nil {
30263125
return nil

0 commit comments

Comments
 (0)