Skip to content

Commit

Permalink
WOOP-302: Add support for policy single resource management (#435)
Browse files Browse the repository at this point in the history
* WOOP-302: syncing API changes

* WOOP-302: adding support for single resource management option.

* WOOP-302: generate docs

* WOOP-302: adding minimum required autoscaler version
  • Loading branch information
JolantaSk authored Jan 8, 2025
1 parent 1aec60f commit 0152881
Show file tree
Hide file tree
Showing 7 changed files with 718 additions and 14 deletions.
15 changes: 15 additions & 0 deletions castai/resource_workload_scaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func workloadScalingPolicyResourceSchema(function string, overhead, minRecommend
Description: "Resource limit settings",
Elem: workloadScalingPolicyResourceLimitSchema(),
},
"management_option": {
Type: schema.TypeString,
Optional: true,
Description: "Disables management for a single resource when set to `READ_ONLY`. " +
"The resource will use its original workload template requests and limits. " +
"Supported value: `READ_ONLY`. Minimum required workload-autoscaler version: `v0.23.1`.",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"READ_ONLY"}, false)),
},
},
}
}
Expand Down Expand Up @@ -513,6 +521,9 @@ func toWorkloadScalingPolicies(obj map[string]interface{}) sdk.Workloadoptimizat
if v, ok := obj[FieldLimitStrategy].([]any); ok && len(v) > 0 {
out.Limit = toWorkloadResourceLimit(v[0].(map[string]any))
}
if v, ok := obj["management_option"].(string); ok && v != "" {
out.ManagementOption = lo.ToPtr(sdk.WorkloadoptimizationV1ManagementOption(v))
}

return out
}
Expand Down Expand Up @@ -556,6 +567,10 @@ func toWorkloadScalingPoliciesMap(p sdk.WorkloadoptimizationV1ResourcePolicies)
m[FieldLimitStrategy] = []map[string]any{limit}
}

if p.ManagementOption != nil {
m["management_option"] = string(*p.ManagementOption)
}

return []map[string]interface{}{m}
}

Expand Down
4 changes: 4 additions & 0 deletions castai/resource_workload_scaling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestAccResourceWorkloadScalingPolicy(t *testing.T) {
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"),
resource.TestCheckResourceAttr(resourceName, "memory.0.management_option", "READ_ONLY"),
),
},
{
Expand Down Expand Up @@ -81,6 +82,7 @@ func TestAccResourceWorkloadScalingPolicy(t *testing.T) {
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, "memory.0.management_option", "READ_ONLY"),
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 @@ -130,6 +132,7 @@ func scalingPolicyConfig(clusterName, projectID, name string) string {
type = "MULTIPLIER"
multiplier = 1.8
}
management_option = "READ_ONLY"
}
}`, name)

Expand Down Expand Up @@ -165,6 +168,7 @@ func scalingPolicyConfigUpdated(clusterName, projectID, name string) string {
limit {
type = "NO_LIMIT"
}
management_option = "READ_ONLY"
}
startup {
period_seconds = 123
Expand Down
136 changes: 122 additions & 14 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0152881

Please sign in to comment.