Skip to content

Commit 3933872

Browse files
committed
chore: update API client generator and API client
1 parent 01cf99b commit 3933872

14 files changed

+2268
-3323
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ jobs:
5959
SSO_CLIENT_ID: ${{ secrets.SSO_CLIENT_ID }}
6060
SSO_CLIENT_SECRET: ${{ secrets.SSO_CLIENT_SECRET }}
6161
SSO_DOMAIN: ${{ secrets.SSO_DOMAIN }}
62+
ACCEPTANCE_TEST_ORGANIZATION_ID: ${{ vars.TF_ACCEPTANCE_TEST_ORGANIZATION_ID }}
6263
run: make testacc
6364

castai/provider_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func testAccPreCheck(t *testing.T) {
5050
t.Fatal("CASTAI_API_TOKEN must be set for acceptance tests")
5151
}
5252

53+
if v := os.Getenv("ACCEPTANCE_TEST_ORGANIZATION_ID"); v == "" {
54+
t.Fatal("ACCEPTANCE_TEST_ORGANIZATION_ID must be set for acceptance tests")
55+
}
56+
5357
if err := testAccProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(nil)); err != nil {
5458
t.Fatal(err)
5559
}

castai/resource_eviction_config.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"github.com/castai/terraform-provider-castai/castai/sdk"
8+
"log"
9+
"time"
10+
911
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1113
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1214
"github.com/samber/lo"
13-
"log"
14-
"time"
15+
16+
"github.com/castai/terraform-provider-castai/castai/sdk"
1517
)
1618

1719
const (
@@ -124,18 +126,18 @@ func resourceEvictionConfig() *schema.Resource {
124126
},
125127
},
126128
FieldEvictionOptionDisabled: {
127-
Type: schema.TypeBool,
128-
Optional: true,
129+
Type: schema.TypeBool,
130+
Optional: true,
129131
Description: "Mark pods as removal disabled",
130132
},
131133
FieldEvictionOptionAggressive: {
132-
Type: schema.TypeBool,
133-
Optional: true,
134+
Type: schema.TypeBool,
135+
Optional: true,
134136
Description: "Apply Aggressive mode to Evictor",
135137
},
136138
FieldEvictionOptionDisposable: {
137-
Type: schema.TypeBool,
138-
Optional: true,
139+
Type: schema.TypeBool,
140+
Optional: true,
139141
Description: "Mark node as disposable",
140142
},
141143
},
@@ -424,7 +426,7 @@ func toPodSelector(in interface{}) (*sdk.CastaiEvictorV1PodSelector, error) {
424426
return nil, err
425427
}
426428

427-
if mls == nil || len(mls.AdditionalProperties) == 0 {
429+
if mls == nil || len(*mls) == 0 {
428430
continue
429431
}
430432

@@ -474,21 +476,21 @@ func toNodeSelector(in interface{}) (*sdk.CastaiEvictorV1NodeSelector, error) {
474476
return &out, nil
475477
}
476478

477-
func toMatchLabels(in interface{}) (*sdk.CastaiEvictorV1LabelSelector_MatchLabels, error) {
479+
func toMatchLabels(in interface{}) (*map[string]string, error) {
478480
mls, ok := in.(map[string]interface{})
479481
if !ok {
480482
return nil, fmt.Errorf("mapping match_labels expecting map[string]interface, got %T %+v", in, in)
481483
}
482484
if len(mls) == 0 {
483485
return nil, nil
484486
}
485-
out := sdk.CastaiEvictorV1LabelSelector_MatchLabels{AdditionalProperties: map[string]string{}}
487+
out := map[string]string{}
486488
for k, v := range mls {
487489
value, ok := v.(string)
488490
if !ok {
489491
return nil, fmt.Errorf("mapping match_labels expecting string, got %T %+v", v, v)
490492
}
491-
out.AdditionalProperties[k] = value
493+
out[k] = value
492494
}
493495

494496
return &out, nil
@@ -507,7 +509,7 @@ func flattenPodSelector(ps *sdk.CastaiEvictorV1PodSelector) []map[string]any {
507509
}
508510
if ps.LabelSelector != nil {
509511
if ps.LabelSelector.MatchLabels != nil {
510-
out[FieldMatchLabels] = ps.LabelSelector.MatchLabels.AdditionalProperties
512+
out[FieldMatchLabels] = *ps.LabelSelector.MatchLabels
511513
}
512514
if ps.LabelSelector.MatchExpressions != nil {
513515
out[FieldMatchExpressions] = flattenMatchExpressions(*ps.LabelSelector.MatchExpressions)
@@ -522,7 +524,7 @@ func flattenNodeSelector(ns *sdk.CastaiEvictorV1NodeSelector) []map[string]any {
522524
}
523525
out := map[string]any{}
524526
if ns.LabelSelector.MatchLabels != nil {
525-
out[FieldMatchLabels] = ns.LabelSelector.MatchLabels.AdditionalProperties
527+
out[FieldMatchLabels] = *ns.LabelSelector.MatchLabels
526528
}
527529
if ns.LabelSelector.MatchExpressions != nil {
528530
out[FieldMatchExpressions] = flattenMatchExpressions(*ns.LabelSelector.MatchExpressions)

castai/resource_eviction_config_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"github.com/castai/terraform-provider-castai/castai/sdk"
8-
mock_sdk "github.com/castai/terraform-provider-castai/castai/sdk/mock"
7+
"io"
8+
"net/http"
9+
"testing"
10+
911
"github.com/golang/mock/gomock"
1012
"github.com/hashicorp/go-cty/cty"
1113
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1214
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1315
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1416
"github.com/samber/lo"
1517
"github.com/stretchr/testify/require"
16-
"io"
17-
"net/http"
18-
"testing"
18+
19+
"github.com/castai/terraform-provider-castai/castai/sdk"
20+
mock_sdk "github.com/castai/terraform-provider-castai/castai/sdk/mock"
1921
)
2022

2123
func TestEvictionConfig_ReadContext(t *testing.T) {
@@ -299,9 +301,9 @@ func TestEvictionConfig_UpdateContext(t *testing.T) {
299301
PodSelector: &sdk.CastaiEvictorV1PodSelector{
300302
Kind: lo.ToPtr("Job"),
301303
LabelSelector: &sdk.CastaiEvictorV1LabelSelector{
302-
MatchLabels: &sdk.CastaiEvictorV1LabelSelector_MatchLabels{AdditionalProperties: map[string]string{
304+
MatchLabels: &map[string]string{
303305
"key1": "value1",
304-
}}}}}
306+
}}}}
305307

306308
newConfig := sdk.CastaiEvictorV1EvictionConfig{
307309
Settings: sdk.CastaiEvictorV1EvictionSettings{Disposable: &sdk.CastaiEvictorV1EvictionSettingsSettingEnabled{Enabled: true}},

castai/resource_hibernation_schedule.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func resourceHibernationSchedule() *schema.Resource {
110110
},
111111

112112
Schema: map[string]*schema.Schema{
113-
FieldServiceAccountOrganizationID: {
113+
FieldHibernationScheduleOrganizationID: {
114114
Type: schema.TypeString,
115115
Optional: true,
116116
Description: "ID of the organization. If not provided, then will attempt to infer it using CAST AI API client.",
@@ -422,7 +422,7 @@ func resourceHibernationScheduleUpdate(ctx context.Context, d *schema.ResourceDa
422422

423423
resp, err := client.HibernationSchedulesAPIUpdateHibernationScheduleWithResponse(ctx, organizationID, d.Id(), req)
424424
if checkErr := sdk.CheckOKResponse(resp, err); checkErr != nil {
425-
return diag.FromErr(checkErr)
425+
return diag.FromErr(fmt.Errorf("could not update hibernation schedule in organization %s: %v", organizationID, checkErr))
426426
}
427427

428428
return readHibernationScheduleIntoState(ctx, d, meta, organizationID, d.Id())
@@ -448,17 +448,17 @@ func resourceHibernationScheduleCreate(ctx context.Context, d *schema.ResourceDa
448448

449449
organizationID, err := getHibernationScheduleOrganizationID(ctx, d, meta)
450450
if err != nil {
451-
return diag.FromErr(err)
451+
return diag.FromErr(fmt.Errorf("could not determine organization id: %v", err))
452452
}
453453

454454
schedule, err := stateToHibernationSchedule(d)
455455
if err != nil {
456-
return diag.FromErr(err)
456+
return diag.FromErr(fmt.Errorf("could not map state to hibernation schedule: %v", err))
457457
}
458458

459459
resp, err := client.HibernationSchedulesAPICreateHibernationScheduleWithResponse(ctx, organizationID, *schedule)
460460
if checkErr := sdk.CheckOKResponse(resp, err); checkErr != nil {
461-
return diag.FromErr(checkErr)
461+
return diag.FromErr(fmt.Errorf("could not create hibernation schedule in organization %s: %v", organizationID, checkErr))
462462
}
463463

464464
d.SetId(*resp.JSON200.Id)
@@ -478,7 +478,7 @@ func resourceHibernationScheduleRead(ctx context.Context, d *schema.ResourceData
478478
func readHibernationScheduleIntoState(ctx context.Context, d *schema.ResourceData, meta any, organizationID, id string) diag.Diagnostics {
479479
schedule, err := getHibernationScheduleById(ctx, meta, organizationID, id)
480480
if err != nil {
481-
return diag.FromErr(err)
481+
return diag.FromErr(fmt.Errorf("could not retrieve hibernation schedule by id in organization %s: %v", organizationID, err))
482482
}
483483
if !d.IsNewResource() && schedule == nil {
484484
tflog.Warn(ctx, "Hibernation schedule not found, removing from state", map[string]any{"id": d.Id()})
@@ -840,7 +840,7 @@ func sectionToNodeConfig(section map[string]interface{}) cluster_autoscaler.Node
840840
ConfigName: lo.Ternary(configName != "", &configName, nil),
841841
SubnetId: lo.Ternary(subnetId != "", &subnetId, nil),
842842
Zone: lo.Ternary(zone != "", &zone, nil),
843-
KubernetesLabels: lo.Ternary(kubernetesLabels != nil && len(kubernetesLabels) != 0, &kubernetesLabels, nil),
843+
KubernetesLabels: lo.Ternary(len(kubernetesLabels) != 0, &kubernetesLabels, nil),
844844
GpuConfig: nodeConfigSectionToGPUConfig(section),
845845
NodeAffinity: nodeConfigSectionToNodeAffinity(section),
846846
KubernetesTaints: nodeConfigSectionToKubernetesTaints(section),

castai/resource_hibernation_schedule_test.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"os"
1011
"testing"
1112

1213
"github.com/golang/mock/gomock"
@@ -227,14 +228,15 @@ func TestHibernationSchedule_CreateContext(t *testing.T) {
227228
func TestAccResourceHibernationSchedule_basic(t *testing.T) {
228229
resourceName := fmt.Sprintf("%v-hibernation-schedule-%v", ResourcePrefix, acctest.RandString(8))
229230
renamedResourceName := fmt.Sprintf("%s %s", resourceName, "renamed")
231+
organizationID := os.Getenv("ACCEPTANCE_TEST_ORGANIZATION_ID")
230232

231233
resource.ParallelTest(t, resource.TestCase{
232234
PreCheck: func() { testAccPreCheck(t) },
233235

234236
ProviderFactories: providerFactories,
235237
Steps: []resource.TestStep{
236238
{
237-
Config: makeInitialHibernationScheduleConfig(resourceName),
239+
Config: makeInitialHibernationScheduleConfig(resourceName, organizationID),
238240
Check: resource.ComposeTestCheckFunc(
239241
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "name", resourceName),
240242
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "enabled", "false"),
@@ -247,9 +249,9 @@ func TestAccResourceHibernationSchedule_basic(t *testing.T) {
247249
},
248250
{
249251
// test edits
250-
Config: makeUpdateHibernationScheduleConfig(renamedResourceName),
252+
Config: makeUpdateHibernationScheduleConfig(renamedResourceName, organizationID),
251253
Check: resource.ComposeTestCheckFunc(
252-
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "name", renamedResourceName),
254+
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "name", renamedResourceName),
253255
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "enabled", "true"),
254256
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "pause_config.0.enabled", "false"),
255257
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "pause_config.0.schedule.0.cron_expression", "1 0 * * *"),
@@ -258,14 +260,6 @@ func TestAccResourceHibernationSchedule_basic(t *testing.T) {
258260
resource.TestCheckResourceAttr("castai_hibernation_schedule.test_hibernation_schedule", "resume_config.0.job_config.0.node_config.0.instance_type", "e2-standard-8"),
259261
),
260262
},
261-
// We keep the ImportState test cases at the end so they will test any newly added fields.
262-
// This way it will also verify that after importing the state the output of `tf plan` is empty.
263-
{
264-
// Import state by ID
265-
ImportState: true,
266-
ResourceName: "castai_hibernation_schedule.test_hibernation_schedule",
267-
ImportStateVerify: true,
268-
},
269263
{
270264
// Import state by name
271265
ImportState: true,
@@ -277,11 +271,12 @@ func TestAccResourceHibernationSchedule_basic(t *testing.T) {
277271
})
278272
}
279273

280-
func makeInitialHibernationScheduleConfig(rName string) string {
274+
func makeInitialHibernationScheduleConfig(rName string, organizationID string) string {
281275
template := `
282276
resource "castai_hibernation_schedule" "test_hibernation_schedule" {
283277
name = %q
284278
enabled = false
279+
organization_id = %q
285280
286281
pause_config {
287282
enabled = true
@@ -308,14 +303,15 @@ resource "castai_hibernation_schedule" "test_hibernation_schedule" {
308303
cluster_assignments {}
309304
}
310305
`
311-
return fmt.Sprintf(template, rName)
306+
return fmt.Sprintf(template, rName, organizationID)
312307
}
313308

314-
func makeUpdateHibernationScheduleConfig(rName string) string {
309+
func makeUpdateHibernationScheduleConfig(rName string, organizationID string) string {
315310
template := `
316311
resource "castai_hibernation_schedule" "test_hibernation_schedule" {
317312
name = %q
318313
enabled = true
314+
organization_id = %q
319315
320316
pause_config {
321317
enabled = false
@@ -342,5 +338,5 @@ resource "castai_hibernation_schedule" "test_hibernation_schedule" {
342338
cluster_assignments {}
343339
}
344340
`
345-
return fmt.Sprintf(template, rName)
341+
return fmt.Sprintf(template, rName, organizationID)
346342
}

castai/resource_node_configuration.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,7 @@ func resourceNodeConfigurationCreate(ctx context.Context, d *schema.ResourceData
645645
req.KubeletConfig = toPtr(m)
646646
}
647647
if v := d.Get(FieldNodeConfigurationTags).(map[string]interface{}); len(v) > 0 {
648-
req.Tags = &sdk.NodeconfigV1NewNodeConfiguration_Tags{
649-
AdditionalProperties: toStringMap(v),
650-
}
648+
req.Tags = lo.ToPtr(toStringMap(v))
651649
}
652650

653651
// Map provider specific configurations.
@@ -720,7 +718,7 @@ func resourceNodeConfigurationRead(ctx context.Context, d *schema.ResourceData,
720718
if err := d.Set(FieldNodeConfigurationContainerRuntime, nodeConfig.ContainerRuntime); err != nil {
721719
return diag.FromErr(fmt.Errorf("setting container runtime: %w", err))
722720
}
723-
if err := d.Set(FieldNodeConfigurationTags, nodeConfig.Tags.AdditionalProperties); err != nil {
721+
if err := d.Set(FieldNodeConfigurationTags, nodeConfig.Tags); err != nil {
724722
return diag.FromErr(fmt.Errorf("setting tags: %w", err))
725723
}
726724

@@ -819,9 +817,7 @@ func resourceNodeConfigurationUpdate(ctx context.Context, d *schema.ResourceData
819817
req.KubeletConfig = toPtr(m)
820818
}
821819
if v := d.Get(FieldNodeConfigurationTags).(map[string]interface{}); len(v) > 0 {
822-
req.Tags = &sdk.NodeconfigV1NodeConfigurationUpdate_Tags{
823-
AdditionalProperties: toStringMap(v),
824-
}
820+
req.Tags = lo.ToPtr(toStringMap(v))
825821
}
826822

827823
// Map provider specific configurations.

castai/resource_node_template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func resourceNodeTemplateRead(ctx context.Context, d *schema.ResourceData, meta
669669
return diag.FromErr(fmt.Errorf("setting constraints: %w", err))
670670
}
671671
}
672-
if err := d.Set(FieldNodeTemplateCustomLabels, nodeTemplate.CustomLabels.AdditionalProperties); err != nil {
672+
if err := d.Set(FieldNodeTemplateCustomLabels, nodeTemplate.CustomLabels); err != nil {
673673
return diag.FromErr(fmt.Errorf("setting custom labels: %w", err))
674674
}
675675
if err := d.Set(FieldNodeTemplateCustomTaints, flattenCustomTaints(nodeTemplate.CustomTaints)); err != nil {
@@ -959,7 +959,7 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s
959959
customLabels[k] = v.(string)
960960
}
961961

962-
req.CustomLabels = &sdk.NodetemplatesV1UpdateNodeTemplate_CustomLabels{AdditionalProperties: customLabels}
962+
req.CustomLabels = &customLabels
963963
}
964964
}
965965

@@ -1046,7 +1046,7 @@ func resourceNodeTemplateCreate(ctx context.Context, d *schema.ResourceData, met
10461046
customLabels[k] = v.(string)
10471047
}
10481048

1049-
req.CustomLabels = &sdk.NodetemplatesV1NewNodeTemplate_CustomLabels{AdditionalProperties: customLabels}
1049+
req.CustomLabels = &customLabels
10501050
}
10511051

10521052
if v, ok := d.Get(FieldNodeTemplateCustomTaints).([]any); ok && len(v) > 0 {

castai/resource_organization_members.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func resourceOrganizationMembersUpdate(ctx context.Context, data *schema.Resourc
293293
})
294294
}
295295

296-
resp, err := client.UsersAPICreateInvitationsWithResponse(ctx, sdk.UsersAPICreateInvitationsJSONBody{
296+
resp, err := client.UsersAPICreateInvitationsWithResponse(ctx, sdk.UsersAPICreateInvitationsJSONRequestBody{
297297
Members: &newMemberships,
298298
})
299299
if err := sdk.CheckOKResponse(resp, err); err != nil {

0 commit comments

Comments
 (0)