Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ jobs:

- name: Plan an AKS example
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_ID_V2 }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_SECRET_V2 }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_SUBSCRIPTION_ID_V2 }}
ARM_TENANT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_TENANT_ID_V2 }}
TF_VAR_cluster_name: gh-aks
TF_VAR_castai_api_token: ${{ secrets.CASTAI_TOKEN }}
TF_VAR_castai_api_url: ${{ secrets.CASTAI_URL }}
TF_VAR_cluster_region: "germanywestcentral"
TF_VAR_subscription_id: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_SUBSCRIPTION_ID }}
TF_VAR_subscription_id: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_SUBSCRIPTION_ID_V2 }}
id: aks_plan_examples
run: make plan-terraform-example EXAMPLE_DIR=examples/aks/aks_cluster
5 changes: 3 additions & 2 deletions castai/resource_workload_scaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ func workloadScalingPolicyResourceLimitSchema() *schema.Resource {
Description: fmt.Sprintf(`Defines limit strategy type.
- %s - removes the resource limit even if it was specified in the workload spec.
- %s - keep existing resource limits. While limits provide stability predictability, they may restrict workloads that need to temporarily burst beyond their allocation.
- %s - used to calculate the resource limit. The final value is determined by multiplying the resource request by the specified factor.`, sdk.NOLIMIT, sdk.KEEPLIMITS, sdk.MULTIPLIER),
- %s - used to calculate the resource limit. The final value is determined by multiplying the resource request by the specified factor.
- %s - maintains the original ratio between requests and limits.`, sdk.NOLIMIT, sdk.KEEPLIMITS, sdk.MULTIPLIER, sdk.MAINTAINRATIO),
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(sdk.MULTIPLIER), string(sdk.KEEPLIMITS), string(sdk.NOLIMIT)}, false)),
},
FieldLimitStrategyMultiplier: {
Expand Down Expand Up @@ -1106,7 +1107,7 @@ func toWorkloadResourceLimit(obj map[string]any) (*sdk.WorkloadoptimizationV1Res
out.OnlyIfOriginalExist = onlyIfOriginalExist
}
switch out.Type {
case sdk.NOLIMIT, sdk.KEEPLIMITS:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit tests as this wasn't covered

case sdk.NOLIMIT, sdk.KEEPLIMITS, sdk.MAINTAINRATIO:
out.Multiplier, err = mustGetValue[float64](obj, FieldLimitStrategyMultiplier)
if err == nil {
return nil, fmt.Errorf(`%q limit type doesn't accept multiplier value`, out.Type)
Expand Down
53 changes: 53 additions & 0 deletions castai/resource_workload_scaling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,59 @@ func Test_validateResourcePolicy(t *testing.T) {
}
}

func Test_toWorkloadScalingPolicies_limit(t *testing.T) {
tests := map[string]struct {
args map[string]any
exp sdk.WorkloadoptimizationV1ResourceLimitStrategy
}{
"maintain ratio": {
args: map[string]any{
"type": "MAINTAIN_RATIO",
},
exp: sdk.WorkloadoptimizationV1ResourceLimitStrategy{
Type: sdk.MAINTAINRATIO,
},
},
"no limit": {
args: map[string]any{
"type": "NO_LIMIT",
},
exp: sdk.WorkloadoptimizationV1ResourceLimitStrategy{
Type: sdk.NOLIMIT,
},
},
"keep limits": {
args: map[string]any{
"type": "KEEP_LIMITS",
},
exp: sdk.WorkloadoptimizationV1ResourceLimitStrategy{
Type: sdk.KEEPLIMITS,
},
},
"multiplier": {
args: map[string]any{
"type": "MULTIPLIER",
"multiplier": 2.5,
},
exp: sdk.WorkloadoptimizationV1ResourceLimitStrategy{
Type: sdk.MULTIPLIER,
Multiplier: lo.ToPtr(2.5),
},
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
args := map[string]any{
"limit": []any{tc.args},
}
got, err := toWorkloadScalingPolicies("cpu", args)
require.NoError(t, err)
require.NotNil(t, got.Limit)
require.Equal(t, tc.exp, *got.Limit)
})
}
}

func Test_toPredictiveScaling(t *testing.T) {
tests := map[string]struct {
args map[string]any
Expand Down
295 changes: 283 additions & 12 deletions castai/sdk/api.gen.go

Large diffs are not rendered by default.

215 changes: 215 additions & 0 deletions castai/sdk/client.gen.go

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

Loading
Loading