Skip to content

Commit 10dd945

Browse files
committed
Merge branch 'master' into KUBE-1393
2 parents 24a2414 + 6d6b87b commit 10dd945

File tree

28 files changed

+900
-190
lines changed

28 files changed

+900
-190
lines changed

castai/resource_node_configuration.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,13 @@ func resourceNodeConfiguration() *schema.Resource {
564564
},
565565
},
566566
},
567+
"on_host_maintenance": {
568+
Type: schema.TypeString,
569+
Optional: true,
570+
Default: nil,
571+
Description: "Maintenance behavior of the instances. If not set, the default value for spot nodes is terminate, and for non-spot nodes, it is migrate.",
572+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"migrate", "terminate"}, true)),
573+
},
567574
FieldNodeConfigurationLoadbalancers: {
568575
Type: schema.TypeList,
569576
Optional: true,
@@ -1508,6 +1515,10 @@ func toGKEConfig(obj map[string]interface{}) *sdk.NodeconfigV1GKEConfig {
15081515
}
15091516
}
15101517

1518+
if v, ok := obj["on_host_maintenance"].(string); ok && v != "" {
1519+
out.OnHostMaintenance = toPtr(sdk.NodeconfigV1GKEConfigOnHostMaintenance(v))
1520+
}
1521+
15111522
if v, ok := obj[FieldNodeConfigurationLoadbalancers].([]interface{}); ok && len(v) > 0 {
15121523
out.LoadBalancers = toGkeLoadBalancers(v)
15131524
}
@@ -1609,6 +1620,9 @@ func flattenGKEConfig(config *sdk.NodeconfigV1GKEConfig) []map[string]interface{
16091620
}
16101621
}
16111622

1623+
if v := config.OnHostMaintenance; v != nil {
1624+
m["on_host_maintenance"] = *v
1625+
}
16121626
if v := config.LoadBalancers; v != nil && len(*v) > 0 {
16131627
m[FieldNodeConfigurationLoadbalancers] = fromGkeLoadBalancers(*v)
16141628
}

castai/resource_node_configuration_gke_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestAccResourceNodeConfiguration_gke(t *testing.T) {
4141
resource.TestCheckResourceAttr(resourceName, "gke.0.network_tags.0", "ab"),
4242
resource.TestCheckResourceAttr(resourceName, "gke.0.network_tags.1", "bc"),
4343
resource.TestCheckResourceAttr(resourceName, "gke.0.zones.#", "0"),
44+
resource.TestCheckResourceAttr(resourceName, "gke.0.on_host_maintenance", "MIGRATE"),
4445
),
4546
},
4647
{
@@ -95,6 +96,7 @@ resource "castai_node_configuration" "test" {
9596
max_pods_per_node = 31
9697
network_tags = ["ab", "bc"]
9798
disk_type = "pd-balanced"
99+
on_host_maintenance = "MIGRATE"
98100
}
99101
}
100102

castai/resource_node_template.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const (
8585
FieldNodeTemplateSharingConfiguration = "sharing_configuration"
8686
FieldNodeTemplateSharedClientsPerGpu = "shared_clients_per_gpu"
8787
FieldNodeTemplateSharedGpuName = "gpu_name"
88+
FieldNodeTemplateClmEnabled = "clm_enabled"
8889
)
8990

9091
const (
@@ -694,6 +695,12 @@ func resourceNodeTemplate() *schema.Resource {
694695
},
695696
},
696697
},
698+
FieldNodeTemplateClmEnabled: {
699+
Type: schema.TypeBool,
700+
Optional: true,
701+
Default: false,
702+
Description: "Marks whether CLM should be enabled for nodes created from this template.",
703+
},
697704
},
698705
}
699706
}
@@ -778,6 +785,11 @@ func resourceNodeTemplateRead(ctx context.Context, d *schema.ResourceData, meta
778785
return diag.FromErr(fmt.Errorf("setting gpu settings: %w", err))
779786
}
780787
}
788+
789+
if err := d.Set(FieldNodeTemplateClmEnabled, nodeTemplate.ClmEnabled); err != nil {
790+
return diag.FromErr(fmt.Errorf("setting clm enabled: %w", err))
791+
}
792+
781793
return nil
782794
}
783795

@@ -1079,6 +1091,7 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s
10791091
FieldNodeTemplateSharingConfiguration,
10801092
FieldNodeTemplateSharedGpuName,
10811093
FieldNodeTemplateSharedClientsPerGpu,
1094+
FieldNodeTemplateClmEnabled,
10821095
) {
10831096
log.Printf("[INFO] Nothing to update in node template")
10841097
return nil
@@ -1152,6 +1165,10 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s
11521165
req.Gpu = toTemplateGpu(v[0].(map[string]any))
11531166
}
11541167

1168+
if v, ok := d.GetOk(FieldNodeTemplateClmEnabled); ok {
1169+
req.ClmEnabled = lo.ToPtr(v.(bool))
1170+
}
1171+
11551172
resp, err := client.NodeTemplatesAPIUpdateNodeTemplateWithResponse(ctx, clusterID, name, req)
11561173
if checkErr := sdk.CheckOKResponse(resp, err); checkErr != nil {
11571174
return diag.FromErr(checkErr)
@@ -1181,6 +1198,7 @@ func resourceNodeTemplateCreate(ctx context.Context, d *schema.ResourceData, met
11811198
IsDefault: lo.ToPtr(isDefault),
11821199
ConfigurationId: lo.ToPtr(d.Get(FieldNodeTemplateConfigurationId).(string)),
11831200
ShouldTaint: lo.ToPtr(d.Get(FieldNodeTemplateShouldTaint).(bool)),
1201+
ClmEnabled: lo.ToPtr(d.Get(FieldNodeTemplateClmEnabled).(bool)),
11841202
}
11851203

11861204
//nolint:staticcheck // Currently no other way to reliably get the value and determine if it is set

castai/resource_node_template_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ name = gpu
261261
rebalancing_config_min_nodes = 0
262262
should_taint = true
263263
Tainted = false
264+
clm_enabled = false
264265
gpu.# = 1
265266
gpu.0.default_shared_clients_per_gpu = 10
266267
gpu.0.enable_time_sharing = true
@@ -410,6 +411,7 @@ func TestNodeTemplateResourceCreate_defaultNodeTemplate(t *testing.T) {
410411
"name": "default-by-castai",
411412
"isEnabled": true,
412413
"isDefault": true,
414+
"clmEnabled": false,
413415
"constraints": {
414416
"spot": false,
415417
"onDemand": true,
@@ -450,6 +452,7 @@ func TestNodeTemplateResourceCreate_defaultNodeTemplate(t *testing.T) {
450452
FieldNodeTemplateIsDefault: cty.BoolVal(true),
451453
FieldNodeTemplateCustomInstancesEnabled: cty.BoolVal(true),
452454
FieldNodeTemplateCustomInstancesWithExtendedMemoryEnabled: cty.BoolVal(true),
455+
FieldNodeTemplateClmEnabled: cty.BoolVal(false),
453456
})
454457
state := terraform.NewInstanceStateShimmedFromValue(val, 0)
455458
state.ID = "default-by-castai"
@@ -480,6 +483,7 @@ func TestNodeTemplateResourceCreate_customNodeTemplate(t *testing.T) {
480483
"configurationName": "default",
481484
"name": "custom-template",
482485
"isEnabled": false,
486+
"clmEnabled": true,
483487
"constraints": {
484488
"spot": false,
485489
"onDemand": true,
@@ -529,6 +533,7 @@ func TestNodeTemplateResourceCreate_customNodeTemplate(t *testing.T) {
529533
FieldNodeTemplateIsEnabled: cty.BoolVal(false),
530534
FieldNodeTemplateCustomInstancesEnabled: cty.BoolVal(true),
531535
FieldNodeTemplateCustomInstancesWithExtendedMemoryEnabled: cty.BoolVal(true),
536+
FieldNodeTemplateClmEnabled: cty.BoolVal(true),
532537
})
533538
state := terraform.NewInstanceStateShimmedFromValue(val, 0)
534539
state.ID = name
@@ -626,6 +631,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) {
626631
resource.TestCheckResourceAttr(resourceName, "name", rName),
627632
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
628633
resource.TestCheckResourceAttr(resourceName, "should_taint", "true"),
634+
resource.TestCheckResourceAttr(resourceName, "clm_enabled", "false"),
629635
resource.TestCheckResourceAttr(resourceName, "custom_instances_enabled", "false"),
630636
resource.TestCheckResourceAttr(resourceName, "custom_instances_with_extended_memory_enabled", "false"),
631637
resource.TestCheckResourceAttr(resourceName, "custom_labels.%", "2"),
@@ -699,6 +705,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) {
699705
resource.TestCheckResourceAttr(resourceName, "name", rName),
700706
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
701707
resource.TestCheckResourceAttr(resourceName, "should_taint", "true"),
708+
resource.TestCheckResourceAttr(resourceName, "clm_enabled", "true"),
702709
resource.TestCheckResourceAttr(resourceName, "custom_instances_enabled", "false"),
703710
resource.TestCheckResourceAttr(resourceName, "custom_instances_with_extended_memory_enabled", "false"),
704711
resource.TestCheckResourceAttr(resourceName, "custom_labels.%", "2"),
@@ -779,6 +786,7 @@ func testAccNodeTemplateConfig(rName, clusterName string) string {
779786
name = %[1]q
780787
configuration_id = castai_node_configuration.test.id
781788
should_taint = true
789+
clm_enabled = false
782790
783791
custom_labels = {
784792
%[1]s-label-key-1 = "%[1]s-label-value-1"
@@ -854,6 +862,7 @@ func testNodeTemplateUpdated(rName, clusterName string) string {
854862
name = %[1]q
855863
configuration_id = castai_node_configuration.test.id
856864
should_taint = true
865+
clm_enabled = true
857866
858867
custom_labels = {
859868
%[1]s-label-key-1 = "%[1]s-label-value-1"

0 commit comments

Comments
 (0)