From 83f10b8c45997ca3881134ac60479e9de6c953dc Mon Sep 17 00:00:00 2001 From: Matas Kaminskas Date: Mon, 19 Feb 2024 14:08:55 +0200 Subject: [PATCH] Fix is_enabled property in node template (#273) * impl * update sdk --- castai/resource_node_template.go | 14 ++-- castai/sdk/api.gen.go | 93 +++++++++++++----------- castai/sdk/client.gen.go | 117 ------------------------------- castai/sdk/mock/client.go | 35 --------- 4 files changed, 60 insertions(+), 199 deletions(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 7695ac4b..e7a6223b 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -3,16 +3,18 @@ package castai import ( "context" "fmt" - "github.com/castai/terraform-provider-castai/castai/sdk" + "log" + "strings" + "time" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/samber/lo" - "log" - "strings" - "time" + + "github.com/castai/terraform-provider-castai/castai/sdk" ) const ( @@ -600,11 +602,11 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s name := d.Get(FieldNodeTemplateName).(string) req := sdk.NodeTemplatesAPIUpdateNodeTemplateJSONRequestBody{} - if v, ok := d.GetOk(FieldNodeTemplateIsDefault); ok { + if v, _ := d.GetOk(FieldNodeTemplateIsDefault); v != nil { req.IsDefault = toPtr(v.(bool)) } - if v, ok := d.GetOk(FieldNodeTemplateIsEnabled); ok { + if v, _ := d.GetOk(FieldNodeTemplateIsEnabled); v != nil { req.IsEnabled = toPtr(v.(bool)) } diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index e38357ca..4b62dba4 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -129,6 +129,11 @@ const ( JobStatusSkipped ScheduledrebalancingV1JobStatus = "JobStatusSkipped" ) +// UsersAPIUpdateOrganizationUserRequest defines model for UsersAPI_UpdateOrganizationUser_request. +type UsersAPIUpdateOrganizationUserRequest struct { + Role *string `json:"role,omitempty"` +} + // Auth token used to authenticate via api. type CastaiAuthtokenV1beta1AuthToken struct { // (read only) Indicates whether the token is active. @@ -333,7 +338,7 @@ type CastaiInventoryV1beta1GetOrganizationReservationsBalanceResponse struct { // CastaiInventoryV1beta1GetOrganizationResourceUsageResponse defines model for castai.inventory.v1beta1.GetOrganizationResourceUsageResponse. type CastaiInventoryV1beta1GetOrganizationResourceUsageResponse struct { - InstanceTypes *[]CastaiInventoryV1beta1InstaceTypeAggregate `json:"instanceTypes,omitempty"` + InstanceTypes *[]CastaiInventoryV1beta1InstanceTypeAggregate `json:"instanceTypes,omitempty"` } // CastaiInventoryV1beta1GetReservationsBalanceResponse defines model for castai.inventory.v1beta1.GetReservationsBalanceResponse. @@ -346,37 +351,6 @@ type CastaiInventoryV1beta1GetReservationsResponse struct { Reservations *[]CastaiInventoryV1beta1ReservationDetails `json:"reservations,omitempty"` } -// CastaiInventoryV1beta1GetResourceUsageResponse defines model for castai.inventory.v1beta1.GetResourceUsageResponse. -type CastaiInventoryV1beta1GetResourceUsageResponse struct { - InstanceTypes *[]CastaiInventoryV1beta1CountableInstanceType `json:"instanceTypes,omitempty"` -} - -// CastaiInventoryV1beta1InstaceTypeAggregate defines model for castai.inventory.v1beta1.InstaceTypeAggregate. -type CastaiInventoryV1beta1InstaceTypeAggregate struct { - AzId *string `json:"azId,omitempty"` - ClusterId *string `json:"clusterId,omitempty"` - Count *int32 `json:"count,omitempty"` - - // InstanceType name. This value is provider specific. - InstanceType *string `json:"instanceType,omitempty"` - - // Price of the instance type. $/hour. - Price *string `json:"price,omitempty"` - - // Provider name of the instance type. - Provider *string `json:"provider,omitempty"` - - // Ram (in MiB) available on the instance type. - Ram *string `json:"ram,omitempty"` - - // Region of the instance type. This value is provider specific. - Region *string `json:"region,omitempty"` - Spot *bool `json:"spot,omitempty"` - - // Vcpu available on the instance type. - Vcpu *string `json:"vcpu,omitempty"` -} - // CastaiInventoryV1beta1InstanceReliability defines model for castai.inventory.v1beta1.InstanceReliability. type CastaiInventoryV1beta1InstanceReliability struct { SpotReclaimRateHigh *string `json:"spotReclaimRateHigh,omitempty"` @@ -437,6 +411,36 @@ type CastaiInventoryV1beta1InstanceType struct { Zones *[]CastaiInventoryV1beta1InstanceZone `json:"zones,omitempty"` } +// CastaiInventoryV1beta1InstanceTypeAggregate defines model for castai.inventory.v1beta1.InstanceTypeAggregate. +type CastaiInventoryV1beta1InstanceTypeAggregate struct { + // Availability zone ID of the instance type. + AzId *string `json:"azId,omitempty"` + ClusterId *string `json:"clusterId,omitempty"` + Count *int32 `json:"count,omitempty"` + + // InstanceType name. This value is provider specific. + InstanceType *string `json:"instanceType,omitempty"` + NodeIds *[]string `json:"nodeIds,omitempty"` + + // Price of the instance type. $/hour. + Price *string `json:"price,omitempty"` + + // Provider name of the instance type. + Provider *string `json:"provider,omitempty"` + + // Ram (in MiB) available on the instance type. + Ram *string `json:"ram,omitempty"` + + // Region of the instance type. This value is provider specific. + Region *string `json:"region,omitempty"` + + // Spot defines if the instance type is a spot instance. + Spot *bool `json:"spot,omitempty"` + + // Vcpu available on the instance type. + Vcpu *string `json:"vcpu,omitempty"` +} + // CastaiInventoryV1beta1InstanceZone defines model for castai.inventory.v1beta1.InstanceZone. type CastaiInventoryV1beta1InstanceZone struct { AttachableGpuDevices *[]CastaiInventoryV1beta1AttachableGPUDevice `json:"attachableGpuDevices,omitempty"` @@ -452,6 +456,12 @@ type CastaiInventoryV1beta1InstanceZone struct { // Describes the network settings for the instance type. type CastaiInventoryV1beta1NetworkInfo struct { + // Base bandwidth in Mbps. + BaseBandwidthMbps *int32 `json:"baseBandwidthMbps,omitempty"` + + // Burst bandwidth in Mbps. It's equal to base bandwidth if not specified. + BurstBandwidthMbps *int32 `json:"burstBandwidthMbps,omitempty"` + // The maximum number of IPv4 addresses per network interface. Ipv4AddressesPerInterface *int32 `json:"ipv4AddressesPerInterface,omitempty"` @@ -473,9 +483,9 @@ type CastaiInventoryV1beta1ReservationBalance struct { // CastaiInventoryV1beta1ReservationBalanceV2 defines model for castai.inventory.v1beta1.ReservationBalanceV2. type CastaiInventoryV1beta1ReservationBalanceV2 struct { - InstanceTypes *[]CastaiInventoryV1beta1InstaceTypeAggregate `json:"instanceTypes,omitempty"` - Reservation *CastaiInventoryV1beta1ReservationDetails `json:"reservation,omitempty"` - Usage *float64 `json:"usage,omitempty"` + InstanceTypes *[]CastaiInventoryV1beta1InstanceTypeAggregate `json:"instanceTypes,omitempty"` + Reservation *CastaiInventoryV1beta1ReservationDetails `json:"reservation,omitempty"` + Usage *float64 `json:"usage,omitempty"` } // CastaiInventoryV1beta1ReservationDetails defines model for castai.inventory.v1beta1.ReservationDetails. @@ -886,6 +896,8 @@ type CastaiUsersV1beta1UserOrganization struct { // name of the organization. Name string `json:"name"` + + // user role in the organization. Role string `json:"role"` } @@ -1256,6 +1268,7 @@ type ExternalclusterV1Node struct { // NodeState contains feedback information about progress on the node provisioning. State *ExternalclusterV1NodeState `json:"state,omitempty"` + SubnetId *string `json:"subnetId"` Taints *[]ExternalclusterV1Taint `json:"taints,omitempty"` Unschedulable *bool `json:"unschedulable,omitempty"` Zone *string `json:"zone,omitempty"` @@ -1473,11 +1486,6 @@ type ExternalclusterV1Zone struct { Name *string `json:"name,omitempty"` } -// InlineObject1 defines model for inline_object_1. -type InlineObject1 struct { - Role *string `json:"role,omitempty"` -} - // NodeconfigV1AKSConfig defines model for nodeconfig.v1.AKSConfig. type NodeconfigV1AKSConfig struct { // Maximum number of pods that can be run on a node, which affects how many IP addresses you will need for each node. @@ -2517,6 +2525,9 @@ type InventoryAPIOverwriteReservationsJSONBody = CastaiInventoryV1beta1GenericRe // UsersAPIAddUserToOrganizationJSONBody defines parameters for UsersAPIAddUserToOrganization. type UsersAPIAddUserToOrganizationJSONBody = CastaiUsersV1beta1NewMembership +// UsersAPIUpdateOrganizationUserJSONBody defines parameters for UsersAPIUpdateOrganizationUser. +type UsersAPIUpdateOrganizationUserJSONBody = UsersAPIUpdateOrganizationUserRequest + // ScheduledRebalancingAPICreateRebalancingScheduleJSONBody defines parameters for ScheduledRebalancingAPICreateRebalancingSchedule. type ScheduledRebalancingAPICreateRebalancingScheduleJSONBody = ScheduledrebalancingV1RebalancingSchedule @@ -2618,7 +2629,7 @@ type InventoryAPIOverwriteReservationsJSONRequestBody = InventoryAPIOverwriteRes type UsersAPIAddUserToOrganizationJSONRequestBody = UsersAPIAddUserToOrganizationJSONBody // UsersAPIUpdateOrganizationUserJSONRequestBody defines body for UsersAPIUpdateOrganizationUser for application/json ContentType. -type UsersAPIUpdateOrganizationUserJSONRequestBody = InlineObject1 +type UsersAPIUpdateOrganizationUserJSONRequestBody = UsersAPIUpdateOrganizationUserJSONBody // ScheduledRebalancingAPICreateRebalancingScheduleJSONRequestBody defines body for ScheduledRebalancingAPICreateRebalancingSchedule for application/json ContentType. type ScheduledRebalancingAPICreateRebalancingScheduleJSONRequestBody = ScheduledRebalancingAPICreateRebalancingScheduleJSONBody diff --git a/castai/sdk/client.gen.go b/castai/sdk/client.gen.go index 6094593d..366819db 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -344,9 +344,6 @@ type ClientInterface interface { // InventoryAPIDeleteReservation request InventoryAPIDeleteReservation(ctx context.Context, organizationId string, reservationId string, reqEditors ...RequestEditorFn) (*http.Response, error) - // InventoryAPIGetResourceUsage request - InventoryAPIGetResourceUsage(ctx context.Context, organizationId string, reqEditors ...RequestEditorFn) (*http.Response, error) - // UsersAPIListOrganizationUsers request UsersAPIListOrganizationUsers(ctx context.Context, organizationId string, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1527,18 +1524,6 @@ func (c *Client) InventoryAPIDeleteReservation(ctx context.Context, organization return c.Client.Do(req) } -func (c *Client) InventoryAPIGetResourceUsage(ctx context.Context, organizationId string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewInventoryAPIGetResourceUsageRequest(c.Server, organizationId) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - func (c *Client) UsersAPIListOrganizationUsers(ctx context.Context, organizationId string, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUsersAPIListOrganizationUsersRequest(c.Server, organizationId) if err != nil { @@ -4702,40 +4687,6 @@ func NewInventoryAPIDeleteReservationRequest(server string, organizationId strin return req, nil } -// NewInventoryAPIGetResourceUsageRequest generates requests for InventoryAPIGetResourceUsage -func NewInventoryAPIGetResourceUsageRequest(server string, organizationId string) (*http.Request, error) { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "organizationId", runtime.ParamLocationPath, organizationId) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/v1/organizations/%s/resource-usage", pathParam0) - if operationPath[0] == '/' { - operationPath = "." + operationPath - } - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - return req, nil -} - // NewUsersAPIListOrganizationUsersRequest generates requests for UsersAPIListOrganizationUsers func NewUsersAPIListOrganizationUsersRequest(server string, organizationId string) (*http.Request, error) { var err error @@ -5701,9 +5652,6 @@ type ClientWithResponsesInterface interface { // InventoryAPIDeleteReservation request InventoryAPIDeleteReservationWithResponse(ctx context.Context, organizationId string, reservationId string) (*InventoryAPIDeleteReservationResponse, error) - // InventoryAPIGetResourceUsage request - InventoryAPIGetResourceUsageWithResponse(ctx context.Context, organizationId string) (*InventoryAPIGetResourceUsageResponse, error) - // UsersAPIListOrganizationUsers request UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) @@ -7816,36 +7764,6 @@ func (r InventoryAPIDeleteReservationResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 -type InventoryAPIGetResourceUsageResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *CastaiInventoryV1beta1GetResourceUsageResponse -} - -// Status returns HTTPResponse.Status -func (r InventoryAPIGetResourceUsageResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r InventoryAPIGetResourceUsageResponse) StatusCode() int { - if r.HTTPResponse != nil { - return r.HTTPResponse.StatusCode - } - return 0 -} - -// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 -// Body returns body of byte array -func (r InventoryAPIGetResourceUsageResponse) GetBody() []byte { - return r.Body -} - -// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 - type UsersAPIListOrganizationUsersResponse struct { Body []byte HTTPResponse *http.Response @@ -9166,15 +9084,6 @@ func (c *ClientWithResponses) InventoryAPIDeleteReservationWithResponse(ctx cont return ParseInventoryAPIDeleteReservationResponse(rsp) } -// InventoryAPIGetResourceUsageWithResponse request returning *InventoryAPIGetResourceUsageResponse -func (c *ClientWithResponses) InventoryAPIGetResourceUsageWithResponse(ctx context.Context, organizationId string) (*InventoryAPIGetResourceUsageResponse, error) { - rsp, err := c.InventoryAPIGetResourceUsage(ctx, organizationId) - if err != nil { - return nil, err - } - return ParseInventoryAPIGetResourceUsageResponse(rsp) -} - // UsersAPIListOrganizationUsersWithResponse request returning *UsersAPIListOrganizationUsersResponse func (c *ClientWithResponses) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) { rsp, err := c.UsersAPIListOrganizationUsers(ctx, organizationId) @@ -11134,32 +11043,6 @@ func ParseInventoryAPIDeleteReservationResponse(rsp *http.Response) (*InventoryA return response, nil } -// ParseInventoryAPIGetResourceUsageResponse parses an HTTP response from a InventoryAPIGetResourceUsageWithResponse call -func ParseInventoryAPIGetResourceUsageResponse(rsp *http.Response) (*InventoryAPIGetResourceUsageResponse, error) { - bodyBytes, err := ioutil.ReadAll(rsp.Body) - defer rsp.Body.Close() - if err != nil { - return nil, err - } - - response := &InventoryAPIGetResourceUsageResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest CastaiInventoryV1beta1GetResourceUsageResponse - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - } - - return response, nil -} - // ParseUsersAPIListOrganizationUsersResponse parses an HTTP response from a UsersAPIListOrganizationUsersWithResponse call func ParseUsersAPIListOrganizationUsersResponse(rsp *http.Response) (*UsersAPIListOrganizationUsersResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index c458d99c..6a7603d5 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -975,26 +975,6 @@ func (mr *MockClientInterfaceMockRecorder) InventoryAPIGetReservationsBalance(ct return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InventoryAPIGetReservationsBalance", reflect.TypeOf((*MockClientInterface)(nil).InventoryAPIGetReservationsBalance), varargs...) } -// InventoryAPIGetResourceUsage mocks base method. -func (m *MockClientInterface) InventoryAPIGetResourceUsage(ctx context.Context, organizationId string, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx, organizationId} - for _, a := range reqEditors { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "InventoryAPIGetResourceUsage", varargs...) - ret0, _ := ret[0].(*http.Response) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// InventoryAPIGetResourceUsage indicates an expected call of InventoryAPIGetResourceUsage. -func (mr *MockClientInterfaceMockRecorder) InventoryAPIGetResourceUsage(ctx, organizationId interface{}, reqEditors ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, organizationId}, reqEditors...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InventoryAPIGetResourceUsage", reflect.TypeOf((*MockClientInterface)(nil).InventoryAPIGetResourceUsage), varargs...) -} - // InventoryAPIOverwriteReservations mocks base method. func (m *MockClientInterface) InventoryAPIOverwriteReservations(ctx context.Context, organizationId string, body sdk.InventoryAPIOverwriteReservationsJSONRequestBody, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -3113,21 +3093,6 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) InventoryAPIGetReservati return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InventoryAPIGetReservationsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).InventoryAPIGetReservationsWithResponse), ctx, organizationId) } -// InventoryAPIGetResourceUsageWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) InventoryAPIGetResourceUsageWithResponse(ctx context.Context, organizationId string) (*sdk.InventoryAPIGetResourceUsageResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InventoryAPIGetResourceUsageWithResponse", ctx, organizationId) - ret0, _ := ret[0].(*sdk.InventoryAPIGetResourceUsageResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// InventoryAPIGetResourceUsageWithResponse indicates an expected call of InventoryAPIGetResourceUsageWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) InventoryAPIGetResourceUsageWithResponse(ctx, organizationId interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InventoryAPIGetResourceUsageWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).InventoryAPIGetResourceUsageWithResponse), ctx, organizationId) -} - // InventoryAPIOverwriteReservationsWithBodyWithResponse mocks base method. func (m *MockClientWithResponsesInterface) InventoryAPIOverwriteReservationsWithBodyWithResponse(ctx context.Context, organizationId, contentType string, body io.Reader) (*sdk.InventoryAPIOverwriteReservationsResponse, error) { m.ctrl.T.Helper()