Skip to content

Commit 90c6fa8

Browse files
author
maximk
committed
chore: update openapi response format
1 parent d55ec89 commit 90c6fa8

11 files changed

+71
-66
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
SHELL := /bin/bash
22

3+
export API_HOST ?= api.cast.ai
34
export API_TAGS ?= ExternalClusterAPI,PoliciesAPI,NodeConfigurationAPI,NodeTemplatesAPI,AuthTokenAPI,ScheduledRebalancingAPI,InventoryAPI,UsersAPI,OperationsAPI,EvictorAPI,SSOAPI,CommitmentsAPI,WorkloadOptimizationAPI,ServiceAccountsAPI,RbacServiceAPI,RuntimeSecurityAPI,AllocationGroupAPI,DboAPI
4-
export SWAGGER_LOCATION ?= https://api.cast.ai/v1/spec/openapi.json
5+
export SWAGGER_LOCATION ?= https://$(API_HOST)/v1/spec/openapi.json
56

67
# To add a new SDK, add a line here in the format: package_name:ApiTagName:spec_location
78
SDK_SPECS := \
8-
cluster_autoscaler:HibernationSchedulesAPI:https://api.cast.ai/spec/cluster-autoscaler/openapi.yaml \
9-
organization_management:EnterpriseAPI:https://api.cast.ai/spec/organization-management/openapi.yaml \
10-
omni:EdgeLocationsAPI,ClustersAPI:https://api.cast.ai/spec/omni/openapi.yaml
9+
cluster_autoscaler:HibernationSchedulesAPI:https://$(API_HOST)/spec/cluster-autoscaler/openapi.yaml \
10+
organization_management:EnterpriseAPI:https://$(API_HOST)/spec/organization-management/openapi.yaml \
11+
omni:EdgeLocationsAPI,ClustersAPI:https://$(API_HOST)/spec/omni/openapi.yaml
1112

1213
default: build
1314

castai/provider_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ func testAccPreCheck(t *testing.T) {
7171
testAccProviderConfigure.Do(func() {
7272
if os.Getenv("CASTAI_API_URL") == "" {
7373
// Run acceptance on dev by default if not set.
74-
os.Setenv("CASTAI_API_URL", "https://api.dev-master.cast.ai")
74+
err := os.Setenv("CASTAI_API_URL", "https://api.dev-master.cast.ai")
75+
if err != nil {
76+
t.Fatal("failed to set CASTAI_API_URL")
77+
}
7578
}
7679

7780
if v := os.Getenv("CASTAI_API_TOKEN"); v == "" {

castai/resource_autoscaler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func getCurrentPolicies(ctx context.Context, client sdk.ClientWithResponsesInter
788788
}
789789

790790
responseBytes, err := io.ReadAll(resp.Body)
791-
defer resp.Body.Close()
791+
defer func() { _ = resp.Body.Close() }()
792792
if err != nil {
793793
return nil, fmt.Errorf("reading response body: %w", err)
794794
}

castai/resource_node_configuration.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ func resourceNodeConfigurationCreate(ctx context.Context, d *schema.ResourceData
731731
return diag.FromErr(checkErr)
732732
}
733733

734-
d.SetId(*resp.JSON200.Id)
734+
d.SetId(resp.JSON200.Id)
735735

736736
return resourceNodeConfigurationRead(ctx, d, meta)
737737
}
@@ -924,7 +924,7 @@ func resourceNodeConfigurationDelete(ctx context.Context, d *schema.ResourceData
924924
return diag.FromErr(err)
925925
}
926926

927-
if *resp.JSON200.Default {
927+
if resp.JSON200.Default {
928928
log.Printf("[WARN] Default node configuration (%s) can't be deleted, removing from state", d.Id())
929929
return nil
930930
}
@@ -1738,8 +1738,8 @@ func nodeConfigStateImporter(ctx context.Context, d *schema.ResourceData, meta i
17381738
}
17391739

17401740
for _, cfg := range *resp.JSON200.Items {
1741-
if lo.FromPtr(cfg.Name) == id {
1742-
d.SetId(toString(cfg.Id))
1741+
if cfg.Name == id {
1742+
d.SetId(toString(&cfg.Id))
17431743
return []*schema.ResourceData{d}, nil
17441744
}
17451745
}

castai/resource_node_configuration_default.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func resourceNodeConfigurationDefaultCreate(ctx context.Context, d *schema.Resou
5454
return diag.FromErr(checkErr)
5555
}
5656

57-
d.SetId(*resp.JSON200.Id)
57+
d.SetId(resp.JSON200.Id)
5858

5959
return resourceNodeConfigurationDefaultRead(ctx, d, meta)
6060
}
@@ -79,8 +79,8 @@ func resourceNodeConfigurationDefaultRead(ctx context.Context, d *schema.Resourc
7979
return diag.FromErr(err)
8080
}
8181

82-
configID := resp.JSON200.Id
83-
if !*resp.JSON200.Default {
82+
configID := &resp.JSON200.Id
83+
if !resp.JSON200.Default {
8484
// If configuration is no longer default, we should trigger state change.
8585
configID = nil
8686
}

castai/resource_node_configuration_eks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func testAccCheckNodeConfigurationDestroy(s *terraform.State) error {
319319
if response.StatusCode() == http.StatusNotFound {
320320
return nil
321321
}
322-
if *response.JSON200.Default {
322+
if response.JSON200.Default {
323323
// Default node config can't be deleted.
324324
return nil
325325
}

castai/resource_node_template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ const (
121121

122122
type nodeSelectorOperatorsSlice []string
123123

124-
var nodeSelectorOperators = nodeSelectorOperatorsSlice{NodeSelectorOperationIn,
124+
var nodeSelectorOperators = nodeSelectorOperatorsSlice{
125+
NodeSelectorOperationIn,
125126
NodeSelectorOperationNotIn,
126127
NodeSelectorOperationExists,
127128
NodeSelectorOperationDoesNot,
@@ -1102,7 +1103,6 @@ func flattenNodeAffinity(affinities []sdk.NodetemplatesV1TemplateConstraintsDedi
11021103
result[FieldNodeTemplateAzName] = lo.FromPtr(item.AzName)
11031104

11041105
if item.Affinity != nil && len(*item.Affinity) > 0 {
1105-
11061106
result[FieldNodeTemplateAffinityName] = lo.Map(*item.Affinity, func(affinity sdk.K8sSelectorV1KubernetesNodeAffinity, index int) map[string]any {
11071107
affinityOperator, ok := nodeSelectorOperators.Get(affinity.Operator)
11081108
if !ok {
@@ -1404,7 +1404,7 @@ func getNodeTemplateByName(ctx context.Context, data *schema.ResourceData, meta
14041404
return nil, fmt.Errorf("%w: %v", ErrFailedToFindTemplateWithName, nodeTemplateName)
14051405
}
14061406

1407-
return t.Template, nil
1407+
return &t.Template, nil
14081408
}
14091409

14101410
func nodeTemplateStateImporter(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {

castai/resource_node_template_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestNodeTemplateResourceReadContext(t *testing.T) {
165165
state.ID = "gpu"
166166

167167
data := resource.Data(state)
168-
//spew.Dump(data)
168+
// spew.Dump(data)
169169
result := resource.ReadContext(ctx, data, provider)
170170
r.Nil(result)
171171
r.False(result.HasError())
@@ -383,17 +383,17 @@ func Test_flattenPriceAdjustmentConfiguration(t *testing.T) {
383383
name: "configuration with adjustments",
384384
input: &sdk.NodetemplatesV1PriceAdjustmentConfiguration{
385385
InstanceTypeAdjustments: &map[string]string{
386-
"r7a.xlarge": "1.0",
387-
"r7i.xlarge": "1.20",
388-
"c6a.xlarge": "0.90",
386+
"r7a.xlarge": "1.0",
387+
"r7i.xlarge": "1.20",
388+
"c6a.xlarge": "0.90",
389389
},
390390
},
391391
want: []map[string]any{
392392
{
393393
FieldNodeTemplateInstanceTypeAdjustments: map[string]string{
394-
"r7a.xlarge": "1.0",
395-
"r7i.xlarge": "1.20",
396-
"c6a.xlarge": "0.90",
394+
"r7a.xlarge": "1.0",
395+
"r7i.xlarge": "1.20",
396+
"c6a.xlarge": "0.90",
397397
},
398398
},
399399
},
@@ -1160,7 +1160,7 @@ func testAccCheckNodeTemplateDestroy(templateName string) func(s *terraform.Stat
11601160
if found, ok := lo.Find(*response.JSON200.Items, func(item sdk.NodetemplatesV1NodeTemplateListItem) bool {
11611161
return lo.FromPtr(item.Template.Name) == templateName
11621162
}); ok {
1163-
return fmt.Errorf("node template %q still exists; %+v", id, *found.Template)
1163+
return fmt.Errorf("node template %q still exists; %+v", id, found.Template)
11641164
}
11651165
return nil
11661166
}

castai/resource_rebalancing_job.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package castai
33
import (
44
"context"
55
"fmt"
6-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
76
"net/http"
87
"strings"
98
"time"
109

10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
11+
1112
"github.com/castai/terraform-provider-castai/castai/sdk"
1213
"github.com/google/uuid"
1314
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -65,7 +66,7 @@ func resourceRebalancingJobCreate(ctx context.Context, d *schema.ResourceData, m
6566
return diag.FromErr(err)
6667
}
6768

68-
jobByScheduleId, found, err := getRebalancingJobByScheduleId(ctx, client, *job.ClusterId, *job.RebalancingScheduleId)
69+
jobByScheduleId, found, err := getRebalancingJobByScheduleId(ctx, client, *job.ClusterId, job.RebalancingScheduleId)
6970
if err != nil {
7071
return diag.FromErr(err)
7172
}
@@ -184,7 +185,7 @@ func stateToRebalancingJob(d *schema.ResourceData) (*sdk.ScheduledrebalancingV1R
184185
Id: lo.ToPtr(d.Id()),
185186
Enabled: lo.ToPtr(d.Get("enabled").(bool)),
186187
ClusterId: lo.ToPtr(d.Get("cluster_id").(string)),
187-
RebalancingScheduleId: lo.ToPtr(d.Get("rebalancing_schedule_id").(string)),
188+
RebalancingScheduleId: d.Get("rebalancing_schedule_id").(string),
188189
}
189190

190191
return &result, nil
@@ -220,8 +221,8 @@ func getRebalancingJobByScheduleName(ctx context.Context, client sdk.ClientWithR
220221
}
221222

222223
scheduleID := *schedule.Id
223-
for _, job := range *resp.JSON200.Jobs {
224-
if *job.RebalancingScheduleId == scheduleID {
224+
for _, job := range resp.JSON200.Jobs {
225+
if job.RebalancingScheduleId == scheduleID {
225226
tflog.Debug(ctx, "job found", map[string]interface{}{
226227
"cluster_id": clusterID,
227228
"schedule_id": scheduleID,
@@ -257,8 +258,8 @@ func getRebalancingJobByScheduleId(ctx context.Context, client sdk.ClientWithRes
257258
if checkErr := sdk.CheckOKResponse(listResp, err); checkErr != nil {
258259
return nil, false, checkErr
259260
}
260-
for _, j := range *listResp.JSON200.Jobs {
261-
if *j.RebalancingScheduleId == scheduleID {
261+
for _, j := range listResp.JSON200.Jobs {
262+
if j.RebalancingScheduleId == scheduleID {
262263
return &j, true, nil
263264
}
264265
}

castai/resource_rebalancing_schedule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func getRebalancingScheduleByName(ctx context.Context, client sdk.ClientWithResp
467467
return nil, checkErr
468468
}
469469

470-
for _, schedule := range *resp.JSON200.Schedules {
470+
for _, schedule := range resp.JSON200.Schedules {
471471
if schedule.Name == name {
472472
return &schedule, nil
473473
}

0 commit comments

Comments
 (0)