Skip to content

Commit

Permalink
Test new props
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Dec 18, 2024
1 parent 079230f commit f41e919
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions castai/resource_workload_scaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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}
Expand Down
20 changes: 20 additions & 0 deletions castai/resource_workload_scaling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
Expand Down Expand Up @@ -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)

Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit f41e919

Please sign in to comment.