Skip to content

Commit 055ce70

Browse files
committed
feat: support for spot reliability on node templates
1 parent f3a4fec commit 055ce70

File tree

7 files changed

+599
-9
lines changed

7 files changed

+599
-9
lines changed

castai/resource_eviction_config_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ func TestEvictionConfig_CreateContext(t *testing.T) {
160160
"matchLabels": {
161161
"key1": "value1"
162162
}
163-
}
163+
},
164+
"replicasMin": null
164165
},
165166
"settings": {
166167
"aggressive": {
@@ -265,7 +266,8 @@ func TestEvictionConfig_UpdateContext(t *testing.T) {
265266
"matchLabels": {
266267
"key1": "value1"
267268
}
268-
}
269+
},
270+
"replicasMin": null
269271
},
270272
"settings": {
271273
"aggressive": {

castai/resource_node_template.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const (
5656
FieldNodeTemplateShouldTaint = "should_taint"
5757
FieldNodeTemplateSpot = "spot"
5858
FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent = "spot_diversity_price_increase_limit_percent"
59+
FieldNodeTemplateSpotReliabilityEnabled = "spot_reliability_enabled"
60+
FieldNodeTemplateSpotReliabilityPriceIncreaseLimitPercent = "spot_reliability_price_increase_limit_percent"
5961
FieldNodeTemplateSpotInterruptionPredictionsEnabled = "spot_interruption_predictions_enabled"
6062
FieldNodeTemplateSpotInterruptionPredictionsType = "spot_interruption_predictions_type"
6163
FieldNodeTemplateStorageOptimized = "storage_optimized"
@@ -235,6 +237,17 @@ func resourceNodeTemplate() *schema.Resource {
235237
Optional: true,
236238
Description: "Allowed node configuration price increase when diversifying instance types. E.g. if the value is 10%, then the overall price of diversified instance types can be 10% higher than the price of the optimal configuration.",
237239
},
240+
FieldNodeTemplateSpotReliabilityEnabled: {
241+
Type: schema.TypeBool,
242+
Default: false,
243+
Optional: true,
244+
Description: "Enable/disable spot reliability. When enabled, autoscaler will create instances with highest reliability score within price increase threshold.",
245+
},
246+
FieldNodeTemplateSpotReliabilityPriceIncreaseLimitPercent: {
247+
Type: schema.TypeInt,
248+
Optional: true,
249+
Description: "Allowed node price increase when using spot reliability on ordering the instance types . E.g. if the value is 10%, then the overall price of instance types can be 10% higher than the price of the optimal configuration.",
250+
},
238251
FieldNodeTemplateSpotInterruptionPredictionsEnabled: {
239252
Type: schema.TypeBool,
240253
Default: false,
@@ -766,6 +779,12 @@ func flattenConstraints(c *sdk.NodetemplatesV1TemplateConstraints) ([]map[string
766779
if c.SpotDiversityPriceIncreaseLimitPercent != nil {
767780
out[FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent] = c.SpotDiversityPriceIncreaseLimitPercent
768781
}
782+
if c.EnableSpotReliability != nil {
783+
out[FieldNodeTemplateSpotReliabilityEnabled] = c.EnableSpotReliability
784+
}
785+
if c.SpotReliabilityPriceIncreaseLimitPercent != nil {
786+
out[FieldNodeTemplateSpotReliabilityPriceIncreaseLimitPercent] = c.SpotReliabilityPriceIncreaseLimitPercent
787+
}
769788
if c.SpotInterruptionPredictionsEnabled != nil {
770789
out[FieldNodeTemplateSpotInterruptionPredictionsEnabled] = c.SpotInterruptionPredictionsEnabled
771790
}
@@ -1347,6 +1366,12 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst
13471366
if v, ok := obj[FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent].(int); ok {
13481367
out.SpotDiversityPriceIncreaseLimitPercent = toPtr(int32(v))
13491368
}
1369+
if v, ok := obj[FieldNodeTemplateSpotReliabilityEnabled].(bool); ok {
1370+
out.EnableSpotReliability = toPtr(v)
1371+
}
1372+
if v, ok := obj[FieldNodeTemplateSpotReliabilityPriceIncreaseLimitPercent].(int); ok {
1373+
out.SpotReliabilityPriceIncreaseLimitPercent = toPtr(int32(v))
1374+
}
13501375
if v, ok := obj[FieldNodeTemplateSpotInterruptionPredictionsEnabled].(bool); ok {
13511376
out.SpotInterruptionPredictionsEnabled = toPtr(v)
13521377
}

castai/resource_node_template_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func TestNodeTemplateResourceReadContext(t *testing.T) {
5454
"fallbackRestoreRateSeconds": 0,
5555
"enableSpotDiversity": false,
5656
"spotDiversityPriceIncreaseLimitPercent": 20,
57+
"enableSpotReliability": true,
58+
"spotReliabilityPriceIncreaseLimitPercent": 10,
5759
"spotInterruptionPredictionsEnabled": true,
5860
"spotInterruptionPredictionsType": "aws-rebalance-recommendations",
5961
"storageOptimized": true,
@@ -223,6 +225,8 @@ constraints.0.resource_limits.0.cpu_limit_enabled = true
223225
constraints.0.resource_limits.0.cpu_limit_max_cores = 20
224226
constraints.0.spot = false
225227
constraints.0.spot_diversity_price_increase_limit_percent = 20
228+
constraints.0.spot_reliability_enabled = true
229+
constraints.0.spot_reliability_price_increase_limit_percent = 10
226230
constraints.0.spot_interruption_predictions_enabled = true
227231
constraints.0.spot_interruption_predictions_type = aws-rebalance-recommendations
228232
constraints.0.storage_optimized = false
@@ -710,8 +714,10 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) {
710714
resource.TestCheckResourceAttr(resourceName, "constraints.0.azs.1", "eu-central-1b"),
711715
resource.TestCheckResourceAttr(resourceName, "constraints.0.azs.2", "eu-central-1c"),
712716
resource.TestCheckResourceAttr(resourceName, "is_default", "false"),
713-
resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "true"),
717+
resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "false"),
714718
resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_diversity_price_increase_limit_percent", "22"),
719+
resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_reliability", "true"),
720+
resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_reliability_price_increase_limit_percent", "15"),
715721
resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_interruption_predictions_enabled", "true"),
716722
resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_interruption_predictions_type", "interruption-predictions"),
717723
resource.TestCheckResourceAttr(resourceName, "constraints.0.custom_priority.#", "2"),
@@ -852,8 +858,10 @@ func testNodeTemplateUpdated(rName, clusterName string) string {
852858
use_spot_fallbacks = true
853859
spot = true
854860
on_demand = true
855-
enable_spot_diversity = true
861+
enable_spot_diversity = false
856862
spot_diversity_price_increase_limit_percent = 22
863+
enable_spot_reliability = true
864+
spot_reliability_price_increase_limit_percent = 15
857865
spot_interruption_predictions_enabled = true
858866
spot_interruption_predictions_type = "interruption-predictions"
859867
fallback_restore_rate_seconds = 1800

0 commit comments

Comments
 (0)