From 98d4c225592ad7531c2e247856f06757a2247b8e Mon Sep 17 00:00:00 2001 From: Jakub Solecki Date: Wed, 21 Aug 2024 17:43:47 +0200 Subject: [PATCH 1/3] unify policies and node templates with the mothership API --- castai/resource_autoscaler.go | 4 ++-- castai/resource_node_template.go | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/castai/resource_autoscaler.go b/castai/resource_autoscaler.go index 46647708..7a91b458 100644 --- a/castai/resource_autoscaler.go +++ b/castai/resource_autoscaler.go @@ -269,14 +269,14 @@ func resourceAutoscaler() *schema.Resource { Optional: true, Default: 1, Description: "defines the minimum allowed amount of CPUs in the whole cluster.", - ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(1, 20)), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)), }, FieldMaxCores: { Type: schema.TypeInt, Optional: true, Default: 20, Description: "defines the maximum allowed amount of vCPUs in the whole cluster.", - ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(2, 1000)), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(2)), }, }, }, diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 69e16051..f791afbb 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -206,10 +206,11 @@ func resourceNodeTemplate() *schema.Resource { Description: "Spot instance fallback constraint - when true, on-demand instances will be created, when spots are unavailable.", }, FieldNodeTemplateFallbackRestoreRateSeconds: { - Type: schema.TypeInt, - Default: 0, - Optional: true, - Description: "Fallback restore rate in seconds: defines how much time should pass before spot fallback should be attempted to be restored to real spot.", + Type: schema.TypeInt, + Default: 1800, + Optional: true, + Description: "Fallback restore rate in seconds: defines how much time should pass before spot fallback should be attempted to be restored to real spot.", + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(60)), }, FieldNodeTemplateEnableSpotDiversity: { Type: schema.TypeBool, @@ -218,9 +219,11 @@ func resourceNodeTemplate() *schema.Resource { Description: "Enable/disable spot diversity policy. When enabled, autoscaler will try to balance between diverse and cost optimal instance types.", }, FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent: { - Type: schema.TypeInt, - Optional: true, - 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.", + Type: schema.TypeInt, + Optional: true, + Default: 20, + 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.", + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)), }, FieldNodeTemplateSpotInterruptionPredictionsEnabled: { Type: schema.TypeBool, From 21c1f43e06c947a12eee84a69070fab8fe94cace Mon Sep 17 00:00:00 2001 From: Jakub Solecki Date: Fri, 23 Aug 2024 11:38:49 +0200 Subject: [PATCH 2/3] generate missing sdk mocks --- castai/sdk/api.gen.go | 6 ++ castai/sdk/client.gen.go | 159 +++----------------------------------- castai/sdk/mock/client.go | 43 +---------- 3 files changed, 20 insertions(+), 188 deletions(-) diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index 02f8c2f3..3981c7ac 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -3887,6 +3887,9 @@ type UsersAPIAddUserToOrganizationJSONBody = CastaiUsersV1beta1NewMembership // UsersAPIUpdateOrganizationUserJSONBody defines parameters for UsersAPIUpdateOrganizationUser. type UsersAPIUpdateOrganizationUserJSONBody = UsersAPIUpdateOrganizationUserRequest +// UsersAPIListUserGroupsJSONBody defines parameters for UsersAPIListUserGroups. +type UsersAPIListUserGroupsJSONBody = map[string]interface{} + // ScheduledRebalancingAPICreateRebalancingScheduleJSONBody defines parameters for ScheduledRebalancingAPICreateRebalancingSchedule. type ScheduledRebalancingAPICreateRebalancingScheduleJSONBody = ScheduledrebalancingV1RebalancingSchedule @@ -4104,6 +4107,9 @@ type UsersAPIAddUserToOrganizationJSONRequestBody = UsersAPIAddUserToOrganizatio // UsersAPIUpdateOrganizationUserJSONRequestBody defines body for UsersAPIUpdateOrganizationUser for application/json ContentType. type UsersAPIUpdateOrganizationUserJSONRequestBody = UsersAPIUpdateOrganizationUserJSONBody +// UsersAPIListUserGroupsJSONRequestBody defines body for UsersAPIListUserGroups for application/json ContentType. +type UsersAPIListUserGroupsJSONRequestBody = UsersAPIListUserGroupsJSONBody + // 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 f540eb6a..17175f96 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -377,8 +377,10 @@ type ClientInterface interface { UsersAPIUpdateOrganizationUser(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // UsersAPIListUserGroups request - UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, reqEditors ...RequestEditorFn) (*http.Response, error) + // UsersAPIListUserGroups request with any body + UsersAPIListUserGroupsWithBody(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1718,8 +1720,8 @@ func (c *Client) UsersAPIRemoveOrganizationUsers(ctx context.Context, organizati return c.Client.Do(req) } -func (c *Client) UsersAPIListOrganizationUsers(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewUsersAPIListOrganizationUsersRequest(c.Server, organizationId, params) +func (c *Client) UsersAPIListOrganizationUsers(ctx context.Context, organizationId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUsersAPIListOrganizationUsersRequest(c.Server, organizationId) if err != nil { return nil, err } @@ -1790,18 +1792,6 @@ func (c *Client) UsersAPIUpdateOrganizationUser(ctx context.Context, organizatio return c.Client.Do(req) } -func (c *Client) UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewUsersAPIListUserGroupsRequest(c.Server, organizationId, userId) - 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) ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewScheduledRebalancingAPIListRebalancingSchedulesRequest(c.Server) if err != nil { @@ -5799,7 +5789,7 @@ func NewUsersAPIRemoveOrganizationUsersRequest(server string, organizationId str } // NewUsersAPIListOrganizationUsersRequest generates requests for UsersAPIListOrganizationUsers -func NewUsersAPIListOrganizationUsersRequest(server string, organizationId string, params *UsersAPIListOrganizationUsersParams) (*http.Request, error) { +func NewUsersAPIListOrganizationUsersRequest(server string, organizationId string) (*http.Request, error) { var err error var pathParam0 string @@ -5824,26 +5814,6 @@ func NewUsersAPIListOrganizationUsersRequest(server string, organizationId strin return nil, err } - queryValues := queryURL.Query() - - if params.IncludeGroups != nil { - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "includeGroups", runtime.ParamLocationQuery, *params.IncludeGroups); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - } - - queryURL.RawQuery = queryValues.Encode() - req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err @@ -5994,47 +5964,6 @@ func NewUsersAPIUpdateOrganizationUserRequestWithBody(server string, organizatio return req, nil } -// NewUsersAPIListUserGroupsRequest generates requests for UsersAPIListUserGroups -func NewUsersAPIListUserGroupsRequest(server string, organizationId string, userId 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 - } - - var pathParam1 string - - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "userId", runtime.ParamLocationPath, userId) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/v1/organizations/%s/users/%s/groups", pathParam0, pathParam1) - 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 -} - // NewScheduledRebalancingAPIListRebalancingSchedulesRequest generates requests for ScheduledRebalancingAPIListRebalancingSchedules func NewScheduledRebalancingAPIListRebalancingSchedulesRequest(server string) (*http.Request, error) { var err error @@ -8241,7 +8170,7 @@ type ClientWithResponsesInterface interface { UsersAPIRemoveOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIRemoveOrganizationUsersParams) (*UsersAPIRemoveOrganizationUsersResponse, error) // UsersAPIListOrganizationUsers request - UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams) (*UsersAPIListOrganizationUsersResponse, error) + UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) // UsersAPIAddUserToOrganization request with any body UsersAPIAddUserToOrganizationWithBodyWithResponse(ctx context.Context, organizationId string, contentType string, body io.Reader) (*UsersAPIAddUserToOrganizationResponse, error) @@ -8256,9 +8185,6 @@ type ClientWithResponsesInterface interface { UsersAPIUpdateOrganizationUserWithResponse(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody) (*UsersAPIUpdateOrganizationUserResponse, error) - // UsersAPIListUserGroups request - UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string) (*UsersAPIListUserGroupsResponse, error) - // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) @@ -10727,36 +10653,6 @@ func (r UsersAPIUpdateOrganizationUserResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 -type UsersAPIListUserGroupsResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *[]CastaiUsersV1beta1GroupRef -} - -// Status returns HTTPResponse.Status -func (r UsersAPIListUserGroupsResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r UsersAPIListUserGroupsResponse) 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 UsersAPIListUserGroupsResponse) GetBody() []byte { - return r.Body -} - -// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 - type ScheduledRebalancingAPIListRebalancingSchedulesResponse struct { Body []byte HTTPResponse *http.Response @@ -12849,8 +12745,8 @@ func (c *ClientWithResponses) UsersAPIRemoveOrganizationUsersWithResponse(ctx co } // UsersAPIListOrganizationUsersWithResponse request returning *UsersAPIListOrganizationUsersResponse -func (c *ClientWithResponses) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams) (*UsersAPIListOrganizationUsersResponse, error) { - rsp, err := c.UsersAPIListOrganizationUsers(ctx, organizationId, params) +func (c *ClientWithResponses) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) { + rsp, err := c.UsersAPIListOrganizationUsers(ctx, organizationId) if err != nil { return nil, err } @@ -12900,15 +12796,6 @@ func (c *ClientWithResponses) UsersAPIUpdateOrganizationUserWithResponse(ctx con return ParseUsersAPIUpdateOrganizationUserResponse(rsp) } -// UsersAPIListUserGroupsWithResponse request returning *UsersAPIListUserGroupsResponse -func (c *ClientWithResponses) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string) (*UsersAPIListUserGroupsResponse, error) { - rsp, err := c.UsersAPIListUserGroups(ctx, organizationId, userId) - if err != nil { - return nil, err - } - return ParseUsersAPIListUserGroupsResponse(rsp) -} - // ScheduledRebalancingAPIListRebalancingSchedulesWithResponse request returning *ScheduledRebalancingAPIListRebalancingSchedulesResponse func (c *ClientWithResponses) ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { rsp, err := c.ScheduledRebalancingAPIListRebalancingSchedules(ctx) @@ -15374,32 +15261,6 @@ func ParseUsersAPIUpdateOrganizationUserResponse(rsp *http.Response) (*UsersAPIU return response, nil } -// ParseUsersAPIListUserGroupsResponse parses an HTTP response from a UsersAPIListUserGroupsWithResponse call -func ParseUsersAPIListUserGroupsResponse(rsp *http.Response) (*UsersAPIListUserGroupsResponse, error) { - bodyBytes, err := ioutil.ReadAll(rsp.Body) - defer rsp.Body.Close() - if err != nil { - return nil, err - } - - response := &UsersAPIListUserGroupsResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest []CastaiUsersV1beta1GroupRef - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - } - - return response, nil -} - // ParseScheduledRebalancingAPIListRebalancingSchedulesResponse parses an HTTP response from a ScheduledRebalancingAPIListRebalancingSchedulesWithResponse call func ParseScheduledRebalancingAPIListRebalancingSchedulesResponse(rsp *http.Response) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index 6fa4398d..7cc9f7e3 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -2735,26 +2735,6 @@ func (mr *MockClientInterfaceMockRecorder) UsersAPIListOrganizations(ctx, params return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizations", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListOrganizations), varargs...) } -// UsersAPIListUserGroups mocks base method. -func (m *MockClientInterface) UsersAPIListUserGroups(ctx context.Context, organizationId, userId string, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx, organizationId, userId} - for _, a := range reqEditors { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "UsersAPIListUserGroups", varargs...) - ret0, _ := ret[0].(*http.Response) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// UsersAPIListUserGroups indicates an expected call of UsersAPIListUserGroups. -func (mr *MockClientInterfaceMockRecorder) UsersAPIListUserGroups(ctx, organizationId, userId interface{}, reqEditors ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, organizationId, userId}, reqEditors...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroups", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListUserGroups), varargs...) -} - // UsersAPIRemoveOrganizationUsers mocks base method. func (m *MockClientInterface) UsersAPIRemoveOrganizationUsers(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -5264,18 +5244,18 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListInvitationsW } // UsersAPIListOrganizationUsersWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *sdk.UsersAPIListOrganizationUsersParams) (*sdk.UsersAPIListOrganizationUsersResponse, error) { +func (m *MockClientWithResponsesInterface) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*sdk.UsersAPIListOrganizationUsersResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UsersAPIListOrganizationUsersWithResponse", ctx, organizationId, params) + ret := m.ctrl.Call(m, "UsersAPIListOrganizationUsersWithResponse", ctx, organizationId) ret0, _ := ret[0].(*sdk.UsersAPIListOrganizationUsersResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // UsersAPIListOrganizationUsersWithResponse indicates an expected call of UsersAPIListOrganizationUsersWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganizationUsersWithResponse(ctx, organizationId, params interface{}) *gomock.Call { +func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganizationUsersWithResponse(ctx, organizationId interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationUsersWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationUsersWithResponse), ctx, organizationId, params) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationUsersWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationUsersWithResponse), ctx, organizationId) } // UsersAPIListOrganizationsWithResponse mocks base method. @@ -5293,21 +5273,6 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganization return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationsWithResponse), ctx, params) } -// UsersAPIListUserGroupsWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId, userId string) (*sdk.UsersAPIListUserGroupsResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UsersAPIListUserGroupsWithResponse", ctx, organizationId, userId) - ret0, _ := ret[0].(*sdk.UsersAPIListUserGroupsResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// UsersAPIListUserGroupsWithResponse indicates an expected call of UsersAPIListUserGroupsWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListUserGroupsWithResponse(ctx, organizationId, userId interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroupsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListUserGroupsWithResponse), ctx, organizationId, userId) -} - // UsersAPIRemoveOrganizationUsersWithResponse mocks base method. func (m *MockClientWithResponsesInterface) UsersAPIRemoveOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams) (*sdk.UsersAPIRemoveOrganizationUsersResponse, error) { m.ctrl.T.Helper() From e0ee8a54f1d088a07d33197b4e4fe0e81dee4bdf Mon Sep 17 00:00:00 2001 From: Jakub Solecki Date: Fri, 23 Aug 2024 11:48:12 +0200 Subject: [PATCH 3/3] revert spot attributes validation from node templates --- castai/resource_node_template.go | 17 ++-- castai/sdk/api.gen.go | 6 -- castai/sdk/client.gen.go | 159 +++++++++++++++++++++++++++++-- castai/sdk/mock/client.go | 43 ++++++++- 4 files changed, 195 insertions(+), 30 deletions(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index f791afbb..69e16051 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -206,11 +206,10 @@ func resourceNodeTemplate() *schema.Resource { Description: "Spot instance fallback constraint - when true, on-demand instances will be created, when spots are unavailable.", }, FieldNodeTemplateFallbackRestoreRateSeconds: { - Type: schema.TypeInt, - Default: 1800, - Optional: true, - Description: "Fallback restore rate in seconds: defines how much time should pass before spot fallback should be attempted to be restored to real spot.", - ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(60)), + Type: schema.TypeInt, + Default: 0, + Optional: true, + Description: "Fallback restore rate in seconds: defines how much time should pass before spot fallback should be attempted to be restored to real spot.", }, FieldNodeTemplateEnableSpotDiversity: { Type: schema.TypeBool, @@ -219,11 +218,9 @@ func resourceNodeTemplate() *schema.Resource { Description: "Enable/disable spot diversity policy. When enabled, autoscaler will try to balance between diverse and cost optimal instance types.", }, FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent: { - Type: schema.TypeInt, - Optional: true, - Default: 20, - 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.", - ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)), + Type: schema.TypeInt, + Optional: true, + 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.", }, FieldNodeTemplateSpotInterruptionPredictionsEnabled: { Type: schema.TypeBool, diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index 3981c7ac..02f8c2f3 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -3887,9 +3887,6 @@ type UsersAPIAddUserToOrganizationJSONBody = CastaiUsersV1beta1NewMembership // UsersAPIUpdateOrganizationUserJSONBody defines parameters for UsersAPIUpdateOrganizationUser. type UsersAPIUpdateOrganizationUserJSONBody = UsersAPIUpdateOrganizationUserRequest -// UsersAPIListUserGroupsJSONBody defines parameters for UsersAPIListUserGroups. -type UsersAPIListUserGroupsJSONBody = map[string]interface{} - // ScheduledRebalancingAPICreateRebalancingScheduleJSONBody defines parameters for ScheduledRebalancingAPICreateRebalancingSchedule. type ScheduledRebalancingAPICreateRebalancingScheduleJSONBody = ScheduledrebalancingV1RebalancingSchedule @@ -4107,9 +4104,6 @@ type UsersAPIAddUserToOrganizationJSONRequestBody = UsersAPIAddUserToOrganizatio // UsersAPIUpdateOrganizationUserJSONRequestBody defines body for UsersAPIUpdateOrganizationUser for application/json ContentType. type UsersAPIUpdateOrganizationUserJSONRequestBody = UsersAPIUpdateOrganizationUserJSONBody -// UsersAPIListUserGroupsJSONRequestBody defines body for UsersAPIListUserGroups for application/json ContentType. -type UsersAPIListUserGroupsJSONRequestBody = UsersAPIListUserGroupsJSONBody - // 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 17175f96..f540eb6a 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -377,10 +377,8 @@ type ClientInterface interface { UsersAPIUpdateOrganizationUser(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // UsersAPIListUserGroups request with any body - UsersAPIListUserGroupsWithBody(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - - UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // UsersAPIListUserGroups request + UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, reqEditors ...RequestEditorFn) (*http.Response, error) // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1720,8 +1718,8 @@ func (c *Client) UsersAPIRemoveOrganizationUsers(ctx context.Context, organizati 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) +func (c *Client) UsersAPIListOrganizationUsers(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUsersAPIListOrganizationUsersRequest(c.Server, organizationId, params) if err != nil { return nil, err } @@ -1792,6 +1790,18 @@ func (c *Client) UsersAPIUpdateOrganizationUser(ctx context.Context, organizatio return c.Client.Do(req) } +func (c *Client) UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUsersAPIListUserGroupsRequest(c.Server, organizationId, userId) + 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) ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewScheduledRebalancingAPIListRebalancingSchedulesRequest(c.Server) if err != nil { @@ -5789,7 +5799,7 @@ func NewUsersAPIRemoveOrganizationUsersRequest(server string, organizationId str } // NewUsersAPIListOrganizationUsersRequest generates requests for UsersAPIListOrganizationUsers -func NewUsersAPIListOrganizationUsersRequest(server string, organizationId string) (*http.Request, error) { +func NewUsersAPIListOrganizationUsersRequest(server string, organizationId string, params *UsersAPIListOrganizationUsersParams) (*http.Request, error) { var err error var pathParam0 string @@ -5814,6 +5824,26 @@ func NewUsersAPIListOrganizationUsersRequest(server string, organizationId strin return nil, err } + queryValues := queryURL.Query() + + if params.IncludeGroups != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "includeGroups", runtime.ParamLocationQuery, *params.IncludeGroups); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err @@ -5964,6 +5994,47 @@ func NewUsersAPIUpdateOrganizationUserRequestWithBody(server string, organizatio return req, nil } +// NewUsersAPIListUserGroupsRequest generates requests for UsersAPIListUserGroups +func NewUsersAPIListUserGroupsRequest(server string, organizationId string, userId 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 + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "userId", runtime.ParamLocationPath, userId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/organizations/%s/users/%s/groups", pathParam0, pathParam1) + 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 +} + // NewScheduledRebalancingAPIListRebalancingSchedulesRequest generates requests for ScheduledRebalancingAPIListRebalancingSchedules func NewScheduledRebalancingAPIListRebalancingSchedulesRequest(server string) (*http.Request, error) { var err error @@ -8170,7 +8241,7 @@ type ClientWithResponsesInterface interface { UsersAPIRemoveOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIRemoveOrganizationUsersParams) (*UsersAPIRemoveOrganizationUsersResponse, error) // UsersAPIListOrganizationUsers request - UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) + UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams) (*UsersAPIListOrganizationUsersResponse, error) // UsersAPIAddUserToOrganization request with any body UsersAPIAddUserToOrganizationWithBodyWithResponse(ctx context.Context, organizationId string, contentType string, body io.Reader) (*UsersAPIAddUserToOrganizationResponse, error) @@ -8185,6 +8256,9 @@ type ClientWithResponsesInterface interface { UsersAPIUpdateOrganizationUserWithResponse(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody) (*UsersAPIUpdateOrganizationUserResponse, error) + // UsersAPIListUserGroups request + UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string) (*UsersAPIListUserGroupsResponse, error) + // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) @@ -10653,6 +10727,36 @@ func (r UsersAPIUpdateOrganizationUserResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 +type UsersAPIListUserGroupsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *[]CastaiUsersV1beta1GroupRef +} + +// Status returns HTTPResponse.Status +func (r UsersAPIListUserGroupsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UsersAPIListUserGroupsResponse) 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 UsersAPIListUserGroupsResponse) GetBody() []byte { + return r.Body +} + +// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 + type ScheduledRebalancingAPIListRebalancingSchedulesResponse struct { Body []byte HTTPResponse *http.Response @@ -12745,8 +12849,8 @@ func (c *ClientWithResponses) UsersAPIRemoveOrganizationUsersWithResponse(ctx co } // UsersAPIListOrganizationUsersWithResponse request returning *UsersAPIListOrganizationUsersResponse -func (c *ClientWithResponses) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*UsersAPIListOrganizationUsersResponse, error) { - rsp, err := c.UsersAPIListOrganizationUsers(ctx, organizationId) +func (c *ClientWithResponses) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *UsersAPIListOrganizationUsersParams) (*UsersAPIListOrganizationUsersResponse, error) { + rsp, err := c.UsersAPIListOrganizationUsers(ctx, organizationId, params) if err != nil { return nil, err } @@ -12796,6 +12900,15 @@ func (c *ClientWithResponses) UsersAPIUpdateOrganizationUserWithResponse(ctx con return ParseUsersAPIUpdateOrganizationUserResponse(rsp) } +// UsersAPIListUserGroupsWithResponse request returning *UsersAPIListUserGroupsResponse +func (c *ClientWithResponses) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string) (*UsersAPIListUserGroupsResponse, error) { + rsp, err := c.UsersAPIListUserGroups(ctx, organizationId, userId) + if err != nil { + return nil, err + } + return ParseUsersAPIListUserGroupsResponse(rsp) +} + // ScheduledRebalancingAPIListRebalancingSchedulesWithResponse request returning *ScheduledRebalancingAPIListRebalancingSchedulesResponse func (c *ClientWithResponses) ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { rsp, err := c.ScheduledRebalancingAPIListRebalancingSchedules(ctx) @@ -15261,6 +15374,32 @@ func ParseUsersAPIUpdateOrganizationUserResponse(rsp *http.Response) (*UsersAPIU return response, nil } +// ParseUsersAPIListUserGroupsResponse parses an HTTP response from a UsersAPIListUserGroupsWithResponse call +func ParseUsersAPIListUserGroupsResponse(rsp *http.Response) (*UsersAPIListUserGroupsResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer rsp.Body.Close() + if err != nil { + return nil, err + } + + response := &UsersAPIListUserGroupsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []CastaiUsersV1beta1GroupRef + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseScheduledRebalancingAPIListRebalancingSchedulesResponse parses an HTTP response from a ScheduledRebalancingAPIListRebalancingSchedulesWithResponse call func ParseScheduledRebalancingAPIListRebalancingSchedulesResponse(rsp *http.Response) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index 7cc9f7e3..6fa4398d 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -2735,6 +2735,26 @@ func (mr *MockClientInterfaceMockRecorder) UsersAPIListOrganizations(ctx, params return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizations", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListOrganizations), varargs...) } +// UsersAPIListUserGroups mocks base method. +func (m *MockClientInterface) UsersAPIListUserGroups(ctx context.Context, organizationId, userId string, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, organizationId, userId} + for _, a := range reqEditors { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UsersAPIListUserGroups", varargs...) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroups indicates an expected call of UsersAPIListUserGroups. +func (mr *MockClientInterfaceMockRecorder) UsersAPIListUserGroups(ctx, organizationId, userId interface{}, reqEditors ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, organizationId, userId}, reqEditors...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroups", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListUserGroups), varargs...) +} + // UsersAPIRemoveOrganizationUsers mocks base method. func (m *MockClientInterface) UsersAPIRemoveOrganizationUsers(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -5244,18 +5264,18 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListInvitationsW } // UsersAPIListOrganizationUsersWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string) (*sdk.UsersAPIListOrganizationUsersResponse, error) { +func (m *MockClientWithResponsesInterface) UsersAPIListOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *sdk.UsersAPIListOrganizationUsersParams) (*sdk.UsersAPIListOrganizationUsersResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UsersAPIListOrganizationUsersWithResponse", ctx, organizationId) + ret := m.ctrl.Call(m, "UsersAPIListOrganizationUsersWithResponse", ctx, organizationId, params) ret0, _ := ret[0].(*sdk.UsersAPIListOrganizationUsersResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // UsersAPIListOrganizationUsersWithResponse indicates an expected call of UsersAPIListOrganizationUsersWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganizationUsersWithResponse(ctx, organizationId interface{}) *gomock.Call { +func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganizationUsersWithResponse(ctx, organizationId, params interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationUsersWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationUsersWithResponse), ctx, organizationId) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationUsersWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationUsersWithResponse), ctx, organizationId, params) } // UsersAPIListOrganizationsWithResponse mocks base method. @@ -5273,6 +5293,21 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganization return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationsWithResponse), ctx, params) } +// UsersAPIListUserGroupsWithResponse mocks base method. +func (m *MockClientWithResponsesInterface) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId, userId string) (*sdk.UsersAPIListUserGroupsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UsersAPIListUserGroupsWithResponse", ctx, organizationId, userId) + ret0, _ := ret[0].(*sdk.UsersAPIListUserGroupsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroupsWithResponse indicates an expected call of UsersAPIListUserGroupsWithResponse. +func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListUserGroupsWithResponse(ctx, organizationId, userId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroupsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListUserGroupsWithResponse), ctx, organizationId, userId) +} + // UsersAPIRemoveOrganizationUsersWithResponse mocks base method. func (m *MockClientWithResponsesInterface) UsersAPIRemoveOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams) (*sdk.UsersAPIRemoveOrganizationUsersResponse, error) { m.ctrl.T.Helper()