Skip to content

Commit d0f7056

Browse files
atnbrgAnthony Berger
and
Anthony Berger
authored
fix: #506 Add autoscaling settings (#543)
* fix: #506 Add autoscaling settings --------- Co-authored-by: Anthony Berger <[email protected]>
1 parent db4646e commit d0f7056

8 files changed

+427
-35
lines changed

ovh/data_cloud_project_kube_nodepool.go

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ func dataSourceCloudProjectKubeNodepool() *schema.Resource {
110110
Description: "Last update date",
111111
Computed: true,
112112
},
113+
"autoscaling_scale_down_unneeded_time_seconds": {
114+
Type: schema.TypeInt,
115+
Description: "scaleDownUnneededTimeSeconds for autoscaling",
116+
Computed: true,
117+
},
118+
"autoscaling_scale_down_unready_time_seconds": {
119+
Type: schema.TypeInt,
120+
Description: "scaleDownUnreadyTimeSeconds for autoscaling",
121+
Computed: true,
122+
},
123+
"autoscaling_scale_down_utilization_threshold": {
124+
Type: schema.TypeFloat,
125+
Description: "scaleDownUtilizationThreshold for autoscaling",
126+
Computed: true,
127+
},
113128
"template": {
114129
Description: "Node pool template",
115130
Optional: true,

ovh/data_cloud_project_kube_nodepool_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ func TestAccCloudProjectKubeNodePoolDataSource_basic(t *testing.T) {
2929
{
3030
Config: config,
3131
Check: resource.ComposeTestCheckFunc(
32-
resource.TestCheckResourceAttr(
33-
"data.ovh_cloud_project_kube_nodepool.poolDataSource", "max_nodes", "2"),
32+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube_nodepool.poolDataSource", "max_nodes", "2"),
33+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube_nodepool.poolDataSource", "autoscaling_scale_down_unneeded_time_seconds", "222"),
34+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube_nodepool.poolDataSource", "autoscaling_scale_down_unready_time_seconds", "2222"),
35+
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube_nodepool.poolDataSource", "autoscaling_scale_down_utilization_threshold", "0.2"),
3436
),
3537
},
3638
},
@@ -52,6 +54,9 @@ resource "ovh_cloud_project_kube_nodepool" "pool" {
5254
desired_nodes = 1
5355
min_nodes = 0
5456
max_nodes = 2
57+
autoscaling_scale_down_unneeded_time_seconds = 222
58+
autoscaling_scale_down_unready_time_seconds = 2222
59+
autoscaling_scale_down_utilization_threshold = 0.2
5560
5661
depends_on = [
5762
ovh_cloud_project_kube.cluster

ovh/helpers/helpers.go

+24
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ func GetNilIntPointerFromData(data interface{}, id string) *int {
256256
return nil
257257
}
258258

259+
func GetNilFloat64PointerFromData(data interface{}, id string) (*float64, error) {
260+
if resourceData, tok := data.(*schema.ResourceData); tok {
261+
if val, ok := resourceData.GetOk(id); ok {
262+
return GetNilFloat64Pointer(val)
263+
}
264+
} else if mapData, tok := data.(map[string]interface{}); tok {
265+
if val, ok := mapData[id]; ok {
266+
return GetNilFloat64Pointer(val)
267+
}
268+
} else {
269+
return nil, fmt.Errorf("expected a *schema.ResourceData or a map[string]interface{} data type but got a %T", data)
270+
}
271+
return nil, nil
272+
}
273+
259274
func GetNilInt64PointerFromData(data interface{}, id string) *int64 {
260275
if resourceData, tok := data.(*schema.ResourceData); tok {
261276
if val, ok := resourceData.GetOk(id); ok {
@@ -293,6 +308,15 @@ func GetNilIntPointer(val interface{}) *int {
293308
return &value
294309
}
295310

311+
func GetNilFloat64Pointer(val interface{}) (*float64, error) {
312+
if val == nil {
313+
return nil, nil
314+
} else if value, ok := val.(float64); ok {
315+
return &value, nil
316+
}
317+
return nil, fmt.Errorf("Expected a float64 value but got a %T", val)
318+
}
319+
296320
func GetNilInt64Pointer(val interface{}) *int64 {
297321
if val == nil {
298322
return nil

ovh/resource_cloud_project_kube_nodepool.go

+18
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
5353
Computed: true,
5454
ForceNew: false,
5555
},
56+
"autoscaling_scale_down_unneeded_time_seconds": {
57+
Description: "scaleDownUnneededTimeSeconds for autoscaling",
58+
Optional: true,
59+
Computed: true,
60+
Type: schema.TypeInt,
61+
},
62+
"autoscaling_scale_down_unready_time_seconds": {
63+
Description: "scaleDownUnreadyTimeSeconds for autoscaling",
64+
Optional: true,
65+
Computed: true,
66+
Type: schema.TypeInt,
67+
},
68+
"autoscaling_scale_down_utilization_threshold": {
69+
Description: "scaleDownUtilizationThreshold for autoscaling",
70+
Optional: true,
71+
Computed: true,
72+
Type: schema.TypeFloat,
73+
},
5674
"anti_affinity": {
5775
Type: schema.TypeBool,
5876
Description: "Enable anti affinity groups for nodes in the pool",

0 commit comments

Comments
 (0)