From f41e9199c302b7b6bdf1b57deb4fbca8fb3b8bc4 Mon Sep 17 00:00:00 2001 From: Mateusz Szostok Date: Wed, 18 Dec 2024 12:58:48 +0100 Subject: [PATCH] Test new props --- castai/resource_workload_scaling_policy.go | 9 ++++++--- .../resource_workload_scaling_policy_test.go | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/castai/resource_workload_scaling_policy.go b/castai/resource_workload_scaling_policy.go index 15f43230..f124e215 100644 --- a/castai/resource_workload_scaling_policy.go +++ b/castai/resource_workload_scaling_policy.go @@ -231,7 +231,7 @@ func workloadScalingPolicyResourceLimitSchema() *schema.Resource { Description: `Defines limit strategy type. - NONE - removes the resource limit even if it was specified in the workload spec. - MULTIPLIER - used to calculate the resource limit. The final value is determined by multiplying the resource request by the specified factor.`, - ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"NONE", "MULTIPLIER"}, true)), // FIXME: any reason to be strict about it? + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(sdk.MULTIPLIER), string(sdk.NOLIMIT)}, true)), // FIXME: any reason to be strict about it? DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool { // FIXME: return strings.EqualFold(oldValue, newValue) }, @@ -550,10 +550,13 @@ func toWorkloadScalingPoliciesMap(p sdk.WorkloadoptimizationV1ResourcePolicies) } if p.Limit != nil { - m[FieldLimitStrategyType] = p.Limit.Type + limit := map[string]any{} + + limit[FieldLimitStrategyType] = p.Limit.Type if p.Limit.Multiplier != nil { - m[FieldLimitStrategyMultiplier] = *p.Limit.Multiplier + limit[FieldLimitStrategyMultiplier] = *p.Limit.Multiplier } + m[FieldLimitStrategy] = []map[string]any{limit} } return []map[string]interface{}{m} diff --git a/castai/resource_workload_scaling_policy_test.go b/castai/resource_workload_scaling_policy_test.go index 5214d0ce..348cadfa 100644 --- a/castai/resource_workload_scaling_policy_test.go +++ b/castai/resource_workload_scaling_policy_test.go @@ -41,11 +41,15 @@ func TestAccResourceWorkloadScalingPolicy(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "cpu.0.look_back_period_seconds", "86401"), resource.TestCheckResourceAttr(resourceName, "cpu.0.min", "0.1"), resource.TestCheckResourceAttr(resourceName, "cpu.0.max", "1"), + resource.TestCheckResourceAttr(resourceName, "cpu.0.limit.0.type", "MULTIPLIER"), + resource.TestCheckResourceAttr(resourceName, "cpu.0.limit.0.multiplier", "1.2"), resource.TestCheckResourceAttr(resourceName, "memory.0.function", "MAX"), resource.TestCheckResourceAttr(resourceName, "memory.0.overhead", "0.25"), resource.TestCheckResourceAttr(resourceName, "memory.0.apply_threshold", "0.1"), resource.TestCheckResourceAttr(resourceName, "memory.0.args.#", "0"), resource.TestCheckResourceAttr(resourceName, "memory.0.min", "100"), + resource.TestCheckResourceAttr(resourceName, "memory.0.limit.0.type", "MULTIPLIER"), + resource.TestCheckResourceAttr(resourceName, "memory.0.limit.0.multiplier", "1.8"), ), }, { @@ -69,12 +73,14 @@ func TestAccResourceWorkloadScalingPolicy(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "cpu.0.args.0", "0.9"), resource.TestCheckResourceAttr(resourceName, "cpu.0.look_back_period_seconds", "86402"), resource.TestCheckResourceAttr(resourceName, "cpu.0.min", "0.1"), + resource.TestCheckResourceAttr(resourceName, "cpu.0.limit.0.type", "NO_LIMIT"), resource.TestCheckResourceAttr(resourceName, "memory.0.function", "QUANTILE"), resource.TestCheckResourceAttr(resourceName, "memory.0.overhead", "0.35"), resource.TestCheckResourceAttr(resourceName, "memory.0.apply_threshold", "0.2"), resource.TestCheckResourceAttr(resourceName, "memory.0.args.0", "0.9"), resource.TestCheckResourceAttr(resourceName, "memory.0.min", "100"), resource.TestCheckResourceAttr(resourceName, "memory.0.max", "512"), + resource.TestCheckResourceAttr(resourceName, "memory.0.limit.0.type", "NO_LIMIT"), resource.TestCheckResourceAttr(resourceName, "startup.0.period_seconds", "123"), resource.TestCheckResourceAttr(resourceName, "downscaling.0.apply_type", "DEFERRED"), resource.TestCheckResourceAttr(resourceName, "memory_event.0.apply_type", "DEFERRED"), @@ -110,12 +116,20 @@ func scalingPolicyConfig(clusterName, projectID, name string) string { min = 0.1 max = 1 look_back_period_seconds = 86401 + limit { + type = "MULTIPLIER" + multiplier = 1.2 + } } memory { function = "MAX" overhead = 0.25 apply_threshold = 0.1 min = 100 + limit { + type = "MULTIPLIER" + multiplier = 1.8 + } } }`, name) @@ -137,6 +151,9 @@ func scalingPolicyConfigUpdated(clusterName, projectID, name string) string { args = ["0.9"] look_back_period_seconds = 86402 min = 0.1 + limit { + type = "NO_LIMIT" + } } memory { function = "QUANTILE" @@ -145,6 +162,9 @@ func scalingPolicyConfigUpdated(clusterName, projectID, name string) string { args = ["0.9"] min = 100 max = 512 + limit { + type = "NO_LIMIT" + } } startup { period_seconds = 123