Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed rightsizing attach, detach workload issue and added support for new rightsizing attributes. #595

Merged
merged 10 commits into from
Nov 13, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

## 1.197.0 (Nov, 13 2024)
ENHANCEMENTS:
* resource/spotinst_ocean_right_sizing_rule: Fixed rightsizing rule attach and detach workloads in subsequent updates.
* resource/spotinst_ocean_right_sizing_rule: Added support for `exclude_preliminary_recommendations`, `recommendation_application_hpa`, and `restart_replicas` attributes.

## 1.196.0 (October, 28 2024)
ENHANCEMENTS:
* resource/spotinst_elastigroup_azure_v3: Added support for `scheduling`, `health`, `load_balancer`, `secrets`, `security` blocks.
Expand Down
194 changes: 194 additions & 0 deletions docs/resources/ocean_automatic_rightsizing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
layout: "spotinst"
page_title: "Spotinst: ocean_right_sizing_rule"
subcategory: "Ocean"
description: |-
Provides a Spotinst Ocean Right Sizing resource.
---

# spotinst\_ocean\_right\_sizing\_rule

Manages a Spotinst Ocean right sizing rule resource.

## Example Usage

```hcl
resource "spotinst_ocean_right_sizing_rule" "example" {
ocean_id = "o-123456"
rule_name = "test-rule"
exclude_preliminary_recommendations= true
restart_replicas="ALL_MANIFEST"

recommendation_application_hpa{
allow_hpa_recommendations= true
}

recommendation_application_intervals {
repetition_basis = "WEEKLY"
weekly_repetition_basis {
interval_days = ["MONDAY", "WEDNESDAY"]
interval_hours_start_time = "12:00"
interval_hours_end_time = "14:00"
}
}


recommendation_application_intervals {
repetition_basis = "MONTHLY"
monthly_repetition_basis {
interval_months = [2,6,9]
week_of_the_month = ["FIRST","LAST"]
weekly_repetition_basis {
interval_days = ["MONDAY"]
interval_hours_start_time = "03:00"
interval_hours_end_time = "04:00"
}
}
}

recommendation_application_boundaries {
cpu_min = 120
cpu_max = 190
memory_min = 160
memory_max = 190
}

recommendation_application_min_threshold {
cpu_percentage = 0.412
memory_percentage = 0.36
}

recommendation_application_overhead_values {
cpu_percentage = 0.80
memory_percentage = 0.50
}

}
```
```

## Argument Reference

The following arguments are supported:

* `ocean_id` - (Required) Identifier of the Ocean cluster.
* `rule_name` - (Required) The unique name of the rule.
* `exclude_preliminary_recommendations` - (Optional) Exclude preliminary recommendations (recommendations based on less than 4 full days of data).
* `restart_replicas` - (Optional) Valid values: "MORE_THAN_ONE_REPLICA" "ALL_MANIFEST" "NO_RESTART". Enable to sequentially restart pod batches according to recommendations, for all pods, only more than 1 replica, or not any pod.
* `recommendation_application_boundaries` - (Optional) Determines the Ocean Rightsizing rule recommendation application boundaries.
* `cpu_min` - (Optional) the minimal value of cpu in vCpu.
* `cpu_max` - (Optional) the maximal value of cpu in vCpu.
* `memory_min` - (Optional) the minimal value of memory in Gib.
* `memory_max` - (Optional) the maximal value of memory in Gib.
* `recommendation_application_hpa` - HPA Rightsizing Rule Recommendation Configuration
* `allow_hpa_recommendations` - Determines by the rule if recommendation application is allowed for workloads with HPA definition.

* `recommendation_application_intervals` - (Required) Determines the Ocean Rightsizing rule recommendation application intervals.
* `repetition_basis` - (Optional) Valid values: "WEEKLY" "MONTHLY". The repetition basis.
* `weekly_repetition_basis` - (Optional) Determines the Ocean Rightsizing rule weekly repetition basis.
* `interval_days` - (Optional) Valid values: "SUNDAY" "MONDAY" "TUESDAY" "WEDNESDAY" "THURSDAY" "FRIDAY" "SATURDAY". Array of the days of the week, when we want to trigger the apply recommendations.
* `interval_hours_start_time` - (Optional) Start time.
* `interval_hours_end_time` - (Optional) End time.
* `monthly_repetition_basis` - (Optional) Determines the Ocean Rightsizing rule monthly repetition basis.
* `interval_months` - (Optional) Array of the months (in number), when we want to trigger the apply recommendations.
* `week_of_the_month` - (Optional) Valid values: "FIRST" "SECOND" "THIRD" "FOURTH" "LAST". Array of the weeks in the month, when we want to trigger the apply recommendations.
* `weekly_repetition_basis` - (Optional) Determines the Ocean Rightsizing rule weekly repetition basis.
* `interval_days` - (Optional) Valid values: "SUNDAY" "MONDAY" "TUESDAY" "WEDNESDAY" "THURSDAY" "FRIDAY" "SATURDAY". Array of the days of the week, when we want to trigger the apply recommendations.
* `interval_hours_start_time` - (Optional) Start time.
* `interval_hours_end_time` - (Optional) End time.

* `recommendation_application_min_threshold` - Determines the extent of difference between current request and recommendation to trigger a change in percentage.
* `cpu_percentage` - (Optional, Default: 0.05) .
* `memory_percentage` - (Optional, Default: 0.05) .

* `recommendation_application_overhead_values` - Determines the Ocean Rightsizing rule recommendation application overhead values.
* `cpu_percentage` - (Optional, Default: 0.1) .
* `memory_percentage` - (Optional, Default: 0.1).
```
<a id="attach_workloads"></a>
## Attach Workloads

* `attach_workloads` - (Optional)
* `namespaces` - (Optional)
* `namespace_name` - (Optional) List of namespaces.
* `workloads` - (Optional) List of workloads.
* `workload_type` - (Optional). The type of the workload.
* `workload_name` - (Optional). The name of the workload.
* `regex_name` - (Optional). The regex for the workload name. Not allowed when using workload_name.
* `labels` - (Optional).
* `key` - (Optional).
* `value` - (Optional) .


```hcl
attach_workloads {
namespaces {
namespace_name = "kube-system"
workloads {
workload_type = "Deployment"
workload_name = "konnectivity-agent"
}
}

namespaces{
namespace_name = "kube-system"
workloads {
workload_type = "DaemonSet"
regex_name = "csi-*"
}
}

namespaces{
namespace_name = "kube-system"
labels{
key = "kubernetes.io/cluster-service"
value = "true"
}
}

}
```

<a id="detach_workloads"></a>
## Detach Workloads

* `detach_workloads` - (Optional)
* `namespaces` - (Optional)
* `namespace_name` - (Optional) List of namespaces.
* `workloads` - (Optional) List of workloads.
* `workload_type` - (Optional). The type of the workload.
* `workload_name` - (Optional). The name of the workload.
* `regex_name` - (Optional). The regex for the workload name.Not allowed when using workload_name.
* `labels` - (Optional).
* `key` - (Optional).
* `value` - (Optional) .


```hcl
detach_workloads {

namespaces {
namespace_name = "kube-system"
workloads {
workload_type = "Deployment"
workload_name = "konnectivity-agent"
}
}

namespaces{
namespace_name = "kube-system"
workloads {
workload_type = "DaemonSet"
regex_name = "csi-*"
}
}

namespaces{
namespace_name = "kube-system"
labels{
key = "kubernetes.io/cluster-service"
value = "true"
}
}
}
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.5.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0
github.com/sethvargo/go-password v0.3.1
github.com/spotinst/spotinst-sdk-go v1.372.0
github.com/spotinst/spotinst-sdk-go v1.373.0
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spotinst/spotinst-sdk-go v1.372.0 h1:B4/+HK3D2Fe0821DOmw5RO4Lrzo2gi7oa6QWWjr5/7A=
github.com/spotinst/spotinst-sdk-go v1.372.0/go.mod h1:Tn4/eb0SFY6IXmxz71CClujvbD/PuT+EO6Ta8v6AML4=
github.com/spotinst/spotinst-sdk-go v1.373.0 h1:7swkwpX3JiLCQx6ZbXbgA36zcmUVgo2ZWUogTLp7aYw=
github.com/spotinst/spotinst-sdk-go v1.373.0/go.mod h1:Tn4/eb0SFY6IXmxz71CClujvbD/PuT+EO6Ta8v6AML4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_extension

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_health

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package elastigroup_azure_launchspecification
import (
"errors"
"fmt"

azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_load_balancer

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_scaling_policies

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package elastigroup_azure_scheduling

import (
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
"strconv"
)

func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_secrets

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
"github.com/spotinst/spotinst-sdk-go/spotinst"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elastigroup_azure_strategy

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3"
Expand Down
4 changes: 4 additions & 0 deletions spotinst/ocean_right_sizing_rule/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
MonthlyWeeklyIntervalDays commons.FieldName = "interval_days"
MonthlyWeeklyIntervalHoursStartTime commons.FieldName = "interval_hours_start_time"
MonthlyWeeklyIntervalHoursEndTime commons.FieldName = "interval_hours_end_time"
ExcludePreliminaryRecommendations commons.FieldName = "exclude_preliminary_recommendations"
RestartReplicas commons.FieldName = "restart_replicas"
RecommendationApplicationHPA commons.FieldName = "recommendation_application_hpa"
AllowHpaRecommendations commons.FieldName = "allow_hpa_recommendations"

RecommendationApplicationBoundaries commons.FieldName = "recommendation_application_boundaries"
CpuMin commons.FieldName = "cpu_min"
Expand Down
Loading
Loading