From c52de24c3440fe55b1591f24f9f2872decf46541 Mon Sep 17 00:00:00 2001 From: Mike Norgate Date: Fri, 19 Apr 2024 11:49:49 +0100 Subject: [PATCH 1/2] Handle tri-state values in node templates --- castai/resource_node_template_test.go | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 1dc79907..26437766 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -388,6 +388,60 @@ func TestNodeTemplateResourceDelete_defaultNodeTemplate(t *testing.T) { " false).", result[0].Detail) } +func TestToTemplateConstraints_HandleTriStateValues(t *testing.T) { + tests := map[string]struct { + val cty.Value + assertions func(*require.Assertions, *sdk.NodetemplatesV1TemplateConstraints) + }{ + "all values empty except one": { + val: cty.ObjectVal(map[string]cty.Value{ + FieldNodeTemplateConstraints: cty.ListVal([]cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + FieldNodeTemplateMaxCpu: cty.NumberIntVal(100), + }), + }), + }), + assertions: func(r *require.Assertions, constraints *sdk.NodetemplatesV1TemplateConstraints) { + r.NotNil(constraints) + r.Nil(constraints.ComputeOptimized) + r.Nil(constraints.StorageOptimized) + r.Nil(constraints.Gpu) + r.Nil(constraints.InstanceFamilies) + r.Nil(constraints.MaxMemory) + r.Nil(constraints.MinMemory) + r.Nil(constraints.MinCpu) + r.Nil(constraints.Spot) + r.Nil(constraints.OnDemand) + r.Nil(constraints.UseSpotFallbacks) + r.Nil(constraints.EnableSpotDiversity) + r.Nil(constraints.SpotDiversityPriceIncreaseLimitPercent) + r.Nil(constraints.SpotInterruptionPredictionsEnabled) + r.Nil(constraints.SpotInterruptionPredictionsType) + r.Nil(constraints.CustomPriority) + r.Nil(constraints.DedicatedNodeAffinity) + r.Nil(constraints.Architectures) + r.Nil(constraints.Os) + r.Nil(constraints.IsGpuOnly) + }, + }, + } + + for name, td := range tests { + t.Run(name, func(t *testing.T) { + r := require.New(t) + resource := resourceNodeTemplate() + state := terraform.NewInstanceStateShimmedFromValue(td.val, 0) + state.ID = "testing-template" + + data := resource.Data(state) + constraintsArray := data.Get(FieldNodeTemplateConstraints).([]any) + constraintsMap := constraintsArray[0].(map[string]any) + result := toTemplateConstraints(constraintsMap, data) + td.assertions(r, result) + }) + } +} + func TestAccResourceNodeTemplate_basic(t *testing.T) { rName := fmt.Sprintf("%v-node-template-%v", ResourcePrefix, acctest.RandString(8)) resourceName := "castai_node_template.test" From 7594afcabae23e4ad1ebb85178ad04997a9392e4 Mon Sep 17 00:00:00 2001 From: linkas45 Date: Fri, 26 Apr 2024 14:22:08 +0700 Subject: [PATCH 2/2] fix --- castai/resource_node_template.go | 18 +-- castai/resource_node_template_test.go | 2 +- castai/sdk/api.gen.go | 72 ++++++--- castai/sdk/client.gen.go | 144 +++++++++++++++++- castai/sdk/mock/client.go | 51 ++++++- .../gke_cluster_autoscaler_policies/castai.tf | 3 - .../version.tf | 1 + 7 files changed, 245 insertions(+), 46 deletions(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 20fc1749..3488dc44 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -207,7 +207,6 @@ func resourceNodeTemplate() *schema.Resource { FieldNodeTemplateStorageOptimized: { Type: schema.TypeBool, Optional: true, - Default: false, Description: "Storage optimized instance constraint - will only pick storage optimized nodes if true", }, FieldNodeTemplateIsGpuOnly: { @@ -219,7 +218,6 @@ func resourceNodeTemplate() *schema.Resource { FieldNodeTemplateComputeOptimized: { Type: schema.TypeBool, Optional: true, - Default: false, Description: "Compute optimized instance constraint - will only pick compute optimized nodes if true.", }, FieldNodeTemplateInstanceFamilies: { @@ -741,7 +739,7 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s } if v, ok := d.Get(FieldNodeTemplateConstraints).([]any); ok && len(v) > 0 { - req.Constraints = toTemplateConstraints(v[0].(map[string]any)) + req.Constraints = toTemplateConstraints(d, v[0].(map[string]any)) } if v, _ := d.GetOk(FieldNodeTemplateCustomInstancesEnabled); v != nil { @@ -812,7 +810,7 @@ func resourceNodeTemplateCreate(ctx context.Context, d *schema.ResourceData, met } if v, ok := d.Get(FieldNodeTemplateConstraints).([]any); ok && len(v) > 0 { - req.Constraints = toTemplateConstraints(v[0].(map[string]any)) + req.Constraints = toTemplateConstraints(d, v[0].(map[string]any)) } if v, _ := d.GetOk(FieldNodeTemplateCustomInstancesEnabled); v != nil { @@ -977,14 +975,15 @@ func flattenCustomTaints(taints *[]sdk.NodetemplatesV1Taint) []map[string]string return ts } -func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConstraints { +func toTemplateConstraints(d *schema.ResourceData, obj map[string]any) *sdk.NodetemplatesV1TemplateConstraints { if obj == nil { return nil } out := &sdk.NodetemplatesV1TemplateConstraints{} - if v, ok := obj[FieldNodeTemplateComputeOptimized].(bool); ok { - out.ComputeOptimized = toPtr(v) + // todo: this must be replaced with tri-state enum as GetOkExists is deprecated + if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + "." + FieldNodeTemplateComputeOptimized); exists { + out.ComputeOptimized = toPtr(v.(bool)) } if v, ok := obj[FieldNodeTemplateFallbackRestoreRateSeconds].(int); ok { out.FallbackRestoreRateSeconds = toPtr(int32(v)) @@ -1023,8 +1022,9 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst out.Spot = toPtr(!v) } } - if v, ok := obj[FieldNodeTemplateStorageOptimized].(bool); ok { - out.StorageOptimized = toPtr(v) + // todo: this must be replaced with tri-state enum as GetOkExists is deprecated + if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + "." + FieldNodeTemplateStorageOptimized); exists { + out.StorageOptimized = toPtr(v.(bool)) } if v, ok := obj[FieldNodeTemplateUseSpotFallbacks].(bool); ok { out.UseSpotFallbacks = toPtr(v) diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 26437766..428c3d35 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -436,7 +436,7 @@ func TestToTemplateConstraints_HandleTriStateValues(t *testing.T) { data := resource.Data(state) constraintsArray := data.Get(FieldNodeTemplateConstraints).([]any) constraintsMap := constraintsArray[0].(map[string]any) - result := toTemplateConstraints(constraintsMap, data) + result := toTemplateConstraints(data, constraintsMap) td.assertions(r, result) }) } diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index 36f7d3a1..42239eae 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -87,8 +87,8 @@ const ( In K8sSelectorV1Operator = "in" Lt K8sSelectorV1Operator = "Lt" Lt1 K8sSelectorV1Operator = "lt" - NotIn K8sSelectorV1Operator = "notIn" - NotInt K8sSelectorV1Operator = "NotInt" + NotIn K8sSelectorV1Operator = "NotIn" + NotIn1 K8sSelectorV1Operator = "notIn" ) // Defines values for NodeconfigV1AKSConfigOsDiskType. @@ -152,6 +152,13 @@ const ( JobStatusSkipped ScheduledrebalancingV1JobStatus = "JobStatusSkipped" ) +// Defines values for ScheduledrebalancingV1TargetNodeSelectionAlgorithm. +const ( + TargetNodeSelectionAlgorithmNormalizedPrice ScheduledrebalancingV1TargetNodeSelectionAlgorithm = "TargetNodeSelectionAlgorithmNormalizedPrice" + TargetNodeSelectionAlgorithmUtilization ScheduledrebalancingV1TargetNodeSelectionAlgorithm = "TargetNodeSelectionAlgorithmUtilization" + TargetNodeSelectionAlgorithmUtilizedPrice ScheduledrebalancingV1TargetNodeSelectionAlgorithm = "TargetNodeSelectionAlgorithmUtilizedPrice" +) + // UsersAPIUpdateOrganizationUserRequest defines model for UsersAPI_UpdateOrganizationUser_request. type UsersAPIUpdateOrganizationUserRequest struct { Role *string `json:"role,omitempty"` @@ -1087,8 +1094,9 @@ type ExternalclusterV1Cluster struct { Status *string `json:"status,omitempty"` // Cluster subnets. - Subnets *[]ExternalclusterV1Subnet `json:"subnets,omitempty"` - Tags *ExternalclusterV1Cluster_Tags `json:"tags,omitempty"` + Subnets *[]ExternalclusterV1Subnet `json:"subnets,omitempty"` + Tags *ExternalclusterV1Cluster_Tags `json:"tags,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` // Cluster zones. Zones *[]ExternalclusterV1Zone `json:"zones,omitempty"` @@ -1516,6 +1524,9 @@ type ExternalclusterV1RegisterClusterRequest struct { // Organization of the cluster. OrganizationId *string `json:"organizationId,omitempty"` + + // Workspace id of the cluster. + WorkspaceId *string `json:"workspaceId,omitempty"` } // ExternalclusterV1Resources defines model for externalcluster.v1.Resources. @@ -1577,7 +1588,7 @@ type K8sSelectorV1KubernetesNodeAffinity struct { Key string `json:"key"` // - IN: In values - // - NotInt: Not int values + // - NotIn: Not in values // - Exists: Just exist // - DoesNotExist: Values does not exist // - Gt: Greater then @@ -1587,7 +1598,7 @@ type K8sSelectorV1KubernetesNodeAffinity struct { } // - IN: In values -// - NotInt: Not int values +// - NotIn: Not in values // - Exists: Just exist // - DoesNotExist: Values does not exist // - Gt: Greater then @@ -1673,6 +1684,11 @@ type NodeconfigV1ListConfigurationsResponse struct { Items *[]NodeconfigV1NodeConfiguration `json:"items,omitempty"` } +// NodeconfigV1ListMaxPodsPresetsResponse defines model for nodeconfig.v1.ListMaxPodsPresetsResponse. +type NodeconfigV1ListMaxPodsPresetsResponse struct { + Presets *[]string `json:"presets,omitempty"` +} + // NodeconfigV1NewNodeConfiguration defines model for nodeconfig.v1.NewNodeConfiguration. type NodeconfigV1NewNodeConfiguration struct { Aks *NodeconfigV1AKSConfig `json:"aks,omitempty"` @@ -1685,8 +1701,11 @@ type NodeconfigV1NewNodeConfiguration struct { // Optional docker daemon configuration properties. Provide only properties that you want to override. Available values https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file DockerConfig *map[string]interface{} `json:"dockerConfig,omitempty"` - Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` - Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` + + // Drain timeout in seconds. Defaults to 0. + DrainTimeoutSec *int32 `json:"drainTimeoutSec"` + Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` + Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` // Image to be used while provisioning the node. If nothing is provided will be resolved to latest available image based on Kubernetes version if possible. Image *string `json:"image"` @@ -1737,8 +1756,11 @@ type NodeconfigV1NodeConfiguration struct { // Optional docker daemon configuration properties. Applicable for EKS only. DockerConfig *map[string]interface{} `json:"dockerConfig"` - Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` - Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` + + // Drain timeout in seconds. Defaults to 0. + DrainTimeoutSec *int32 `json:"drainTimeoutSec"` + Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` + Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` // The node configuration ID. Id *string `json:"id,omitempty"` @@ -1792,8 +1814,11 @@ type NodeconfigV1NodeConfigurationUpdate struct { // Optional docker daemon configuration properties. Provide only properties that you want to override. Available values https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file DockerConfig *map[string]interface{} `json:"dockerConfig,omitempty"` - Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` - Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` + + // Drain timeout in seconds. Defaults to 0. + DrainTimeoutSec *int32 `json:"drainTimeoutSec"` + Eks *NodeconfigV1EKSConfig `json:"eks,omitempty"` + Gke *NodeconfigV1GKEConfig `json:"gke,omitempty"` // Image to be used while provisioning the node. If nothing is provided will be resolved to latest available image based on Kubernetes version if possible. Image *string `json:"image"` @@ -2117,9 +2142,11 @@ type NodetemplatesV1TemplateConstraintsCustomPriority struct { // NodetemplatesV1TemplateConstraintsDedicatedNodeAffinity defines model for nodetemplates.v1.TemplateConstraints.DedicatedNodeAffinity. type NodetemplatesV1TemplateConstraintsDedicatedNodeAffinity struct { - AzName *string `json:"azName,omitempty"` - InstanceTypes *[]string `json:"instanceTypes,omitempty"` - Name *string `json:"name,omitempty"` + // The affinity rules required for choosing the node. + Affinity *[]K8sSelectorV1KubernetesNodeAffinity `json:"affinity,omitempty"` + AzName *string `json:"azName,omitempty"` + InstanceTypes *[]string `json:"instanceTypes,omitempty"` + Name *string `json:"name,omitempty"` } // NodetemplatesV1TemplateConstraintsGPUConstraints defines model for nodetemplates.v1.TemplateConstraints.GPUConstraints. @@ -2424,9 +2451,10 @@ type ScheduledrebalancingV1LaunchConfiguration struct { NodeTtlSeconds *int32 `json:"nodeTtlSeconds,omitempty"` // Maximum number of nodes that will be selected for rebalancing. - NumTargetedNodes *int32 `json:"numTargetedNodes,omitempty"` - RebalancingOptions *ScheduledrebalancingV1RebalancingOptions `json:"rebalancingOptions,omitempty"` - Selector *ScheduledrebalancingV1NodeSelector `json:"selector,omitempty"` + NumTargetedNodes *int32 `json:"numTargetedNodes,omitempty"` + RebalancingOptions *ScheduledrebalancingV1RebalancingOptions `json:"rebalancingOptions,omitempty"` + Selector *ScheduledrebalancingV1NodeSelector `json:"selector,omitempty"` + TargetNodeSelectionAlgorithm *ScheduledrebalancingV1TargetNodeSelectionAlgorithm `json:"targetNodeSelectionAlgorithm,omitempty"` } // ScheduledrebalancingV1ListAvailableRebalancingTZResponse defines model for scheduledrebalancing.v1.ListAvailableRebalancingTZResponse. @@ -2534,6 +2562,9 @@ type ScheduledrebalancingV1Schedule struct { Cron string `json:"cron"` } +// ScheduledrebalancingV1TargetNodeSelectionAlgorithm defines model for scheduledrebalancing.v1.TargetNodeSelectionAlgorithm. +type ScheduledrebalancingV1TargetNodeSelectionAlgorithm string + // ScheduledrebalancingV1TimeZone defines model for scheduledrebalancing.v1.TimeZone. type ScheduledrebalancingV1TimeZone struct { Name *string `json:"name,omitempty"` @@ -2602,6 +2633,11 @@ type NodeTemplatesAPIUpdateNodeTemplateJSONBody = NodetemplatesV1UpdateNodeTempl // PoliciesAPIUpsertClusterPoliciesJSONBody defines parameters for PoliciesAPIUpsertClusterPolicies. type PoliciesAPIUpsertClusterPoliciesJSONBody = PoliciesV1Policies +// ScheduledRebalancingAPIListRebalancingJobsParams defines parameters for ScheduledRebalancingAPIListRebalancingJobs. +type ScheduledRebalancingAPIListRebalancingJobsParams struct { + RebalancingScheduleId *string `form:"rebalancingScheduleId,omitempty" json:"rebalancingScheduleId,omitempty"` +} + // ScheduledRebalancingAPICreateRebalancingJobJSONBody defines parameters for ScheduledRebalancingAPICreateRebalancingJob. type ScheduledRebalancingAPICreateRebalancingJobJSONBody = ScheduledrebalancingV1RebalancingJob diff --git a/castai/sdk/client.gen.go b/castai/sdk/client.gen.go index 158c367d..43fc96bd 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -194,7 +194,7 @@ type ClientInterface interface { PoliciesAPIUpsertClusterPolicies(ctx context.Context, clusterId string, body PoliciesAPIUpsertClusterPoliciesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // ScheduledRebalancingAPIListRebalancingJobs request - ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) + ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, params *ScheduledRebalancingAPIListRebalancingJobsParams, reqEditors ...RequestEditorFn) (*http.Response, error) // ScheduledRebalancingAPICreateRebalancingJob request with any body ScheduledRebalancingAPICreateRebalancingJobWithBody(ctx context.Context, clusterId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -297,6 +297,9 @@ type ClientInterface interface { // ExternalClusterAPICreateClusterToken request ExternalClusterAPICreateClusterToken(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) + // NodeConfigurationAPIListMaxPodsPresets request + NodeConfigurationAPIListMaxPodsPresets(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // UsersAPICurrentUserProfile request UsersAPICurrentUserProfile(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -872,8 +875,8 @@ func (c *Client) PoliciesAPIUpsertClusterPolicies(ctx context.Context, clusterId return c.Client.Do(req) } -func (c *Client) ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewScheduledRebalancingAPIListRebalancingJobsRequest(c.Server, clusterId) +func (c *Client) ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, params *ScheduledRebalancingAPIListRebalancingJobsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewScheduledRebalancingAPIListRebalancingJobsRequest(c.Server, clusterId, params) if err != nil { return nil, err } @@ -1328,6 +1331,18 @@ func (c *Client) ExternalClusterAPICreateClusterToken(ctx context.Context, clust return c.Client.Do(req) } +func (c *Client) NodeConfigurationAPIListMaxPodsPresets(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewNodeConfigurationAPIListMaxPodsPresetsRequest(c.Server) + 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) UsersAPICurrentUserProfile(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUsersAPICurrentUserProfileRequest(c.Server) if err != nil { @@ -3012,7 +3027,7 @@ func NewPoliciesAPIUpsertClusterPoliciesRequestWithBody(server string, clusterId } // NewScheduledRebalancingAPIListRebalancingJobsRequest generates requests for ScheduledRebalancingAPIListRebalancingJobs -func NewScheduledRebalancingAPIListRebalancingJobsRequest(server string, clusterId string) (*http.Request, error) { +func NewScheduledRebalancingAPIListRebalancingJobsRequest(server string, clusterId string, params *ScheduledRebalancingAPIListRebalancingJobsParams) (*http.Request, error) { var err error var pathParam0 string @@ -3037,6 +3052,26 @@ func NewScheduledRebalancingAPIListRebalancingJobsRequest(server string, cluster return nil, err } + queryValues := queryURL.Query() + + if params.RebalancingScheduleId != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "rebalancingScheduleId", runtime.ParamLocationQuery, *params.RebalancingScheduleId); 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 @@ -4245,6 +4280,33 @@ func NewExternalClusterAPICreateClusterTokenRequest(server string, clusterId str return req, nil } +// NewNodeConfigurationAPIListMaxPodsPresetsRequest generates requests for NodeConfigurationAPIListMaxPodsPresets +func NewNodeConfigurationAPIListMaxPodsPresetsRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/kubernetes/maxpods-formula-presets") + 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 +} + // NewUsersAPICurrentUserProfileRequest generates requests for UsersAPICurrentUserProfile func NewUsersAPICurrentUserProfileRequest(server string) (*http.Request, error) { var err error @@ -5643,7 +5705,7 @@ type ClientWithResponsesInterface interface { PoliciesAPIUpsertClusterPoliciesWithResponse(ctx context.Context, clusterId string, body PoliciesAPIUpsertClusterPoliciesJSONRequestBody) (*PoliciesAPIUpsertClusterPoliciesResponse, error) // ScheduledRebalancingAPIListRebalancingJobs request - ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string) (*ScheduledRebalancingAPIListRebalancingJobsResponse, error) + ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string, params *ScheduledRebalancingAPIListRebalancingJobsParams) (*ScheduledRebalancingAPIListRebalancingJobsResponse, error) // ScheduledRebalancingAPICreateRebalancingJob request with any body ScheduledRebalancingAPICreateRebalancingJobWithBodyWithResponse(ctx context.Context, clusterId string, contentType string, body io.Reader) (*ScheduledRebalancingAPICreateRebalancingJobResponse, error) @@ -5746,6 +5808,9 @@ type ClientWithResponsesInterface interface { // ExternalClusterAPICreateClusterToken request ExternalClusterAPICreateClusterTokenWithResponse(ctx context.Context, clusterId string) (*ExternalClusterAPICreateClusterTokenResponse, error) + // NodeConfigurationAPIListMaxPodsPresets request + NodeConfigurationAPIListMaxPodsPresetsWithResponse(ctx context.Context) (*NodeConfigurationAPIListMaxPodsPresetsResponse, error) + // UsersAPICurrentUserProfile request UsersAPICurrentUserProfileWithResponse(ctx context.Context) (*UsersAPICurrentUserProfileResponse, error) @@ -7523,6 +7588,36 @@ func (r ExternalClusterAPICreateClusterTokenResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 +type NodeConfigurationAPIListMaxPodsPresetsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *NodeconfigV1ListMaxPodsPresetsResponse +} + +// Status returns HTTPResponse.Status +func (r NodeConfigurationAPIListMaxPodsPresetsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r NodeConfigurationAPIListMaxPodsPresetsResponse) 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 NodeConfigurationAPIListMaxPodsPresetsResponse) GetBody() []byte { + return r.Body +} + +// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 + type UsersAPICurrentUserProfileResponse struct { Body []byte HTTPResponse *http.Response @@ -8813,8 +8908,8 @@ func (c *ClientWithResponses) PoliciesAPIUpsertClusterPoliciesWithResponse(ctx c } // ScheduledRebalancingAPIListRebalancingJobsWithResponse request returning *ScheduledRebalancingAPIListRebalancingJobsResponse -func (c *ClientWithResponses) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string) (*ScheduledRebalancingAPIListRebalancingJobsResponse, error) { - rsp, err := c.ScheduledRebalancingAPIListRebalancingJobs(ctx, clusterId) +func (c *ClientWithResponses) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string, params *ScheduledRebalancingAPIListRebalancingJobsParams) (*ScheduledRebalancingAPIListRebalancingJobsResponse, error) { + rsp, err := c.ScheduledRebalancingAPIListRebalancingJobs(ctx, clusterId, params) if err != nil { return nil, err } @@ -9144,6 +9239,15 @@ func (c *ClientWithResponses) ExternalClusterAPICreateClusterTokenWithResponse(c return ParseExternalClusterAPICreateClusterTokenResponse(rsp) } +// NodeConfigurationAPIListMaxPodsPresetsWithResponse request returning *NodeConfigurationAPIListMaxPodsPresetsResponse +func (c *ClientWithResponses) NodeConfigurationAPIListMaxPodsPresetsWithResponse(ctx context.Context) (*NodeConfigurationAPIListMaxPodsPresetsResponse, error) { + rsp, err := c.NodeConfigurationAPIListMaxPodsPresets(ctx) + if err != nil { + return nil, err + } + return ParseNodeConfigurationAPIListMaxPodsPresetsResponse(rsp) +} + // UsersAPICurrentUserProfileWithResponse request returning *UsersAPICurrentUserProfileResponse func (c *ClientWithResponses) UsersAPICurrentUserProfileWithResponse(ctx context.Context) (*UsersAPICurrentUserProfileResponse, error) { rsp, err := c.UsersAPICurrentUserProfile(ctx) @@ -10940,6 +11044,32 @@ func ParseExternalClusterAPICreateClusterTokenResponse(rsp *http.Response) (*Ext return response, nil } +// ParseNodeConfigurationAPIListMaxPodsPresetsResponse parses an HTTP response from a NodeConfigurationAPIListMaxPodsPresetsWithResponse call +func ParseNodeConfigurationAPIListMaxPodsPresetsResponse(rsp *http.Response) (*NodeConfigurationAPIListMaxPodsPresetsResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer rsp.Body.Close() + if err != nil { + return nil, err + } + + response := &NodeConfigurationAPIListMaxPodsPresetsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest NodeconfigV1ListMaxPodsPresetsResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseUsersAPICurrentUserProfileResponse parses an HTTP response from a UsersAPICurrentUserProfileWithResponse call func ParseUsersAPICurrentUserProfileResponse(rsp *http.Response) (*UsersAPICurrentUserProfileResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index a134930f..830709eb 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -1195,6 +1195,26 @@ func (mr *MockClientInterfaceMockRecorder) NodeConfigurationAPIListConfiguration return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeConfigurationAPIListConfigurations", reflect.TypeOf((*MockClientInterface)(nil).NodeConfigurationAPIListConfigurations), varargs...) } +// NodeConfigurationAPIListMaxPodsPresets mocks base method. +func (m *MockClientInterface) NodeConfigurationAPIListMaxPodsPresets(ctx context.Context, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range reqEditors { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "NodeConfigurationAPIListMaxPodsPresets", varargs...) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NodeConfigurationAPIListMaxPodsPresets indicates an expected call of NodeConfigurationAPIListMaxPodsPresets. +func (mr *MockClientInterfaceMockRecorder) NodeConfigurationAPIListMaxPodsPresets(ctx interface{}, reqEditors ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, reqEditors...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeConfigurationAPIListMaxPodsPresets", reflect.TypeOf((*MockClientInterface)(nil).NodeConfigurationAPIListMaxPodsPresets), varargs...) +} + // NodeConfigurationAPISetDefault mocks base method. func (m *MockClientInterface) NodeConfigurationAPISetDefault(ctx context.Context, clusterId, id string, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -1856,9 +1876,9 @@ func (mr *MockClientInterfaceMockRecorder) ScheduledRebalancingAPIListAvailableR } // ScheduledRebalancingAPIListRebalancingJobs mocks base method. -func (m *MockClientInterface) ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { +func (m *MockClientInterface) ScheduledRebalancingAPIListRebalancingJobs(ctx context.Context, clusterId string, params *sdk.ScheduledRebalancingAPIListRebalancingJobsParams, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, clusterId} + varargs := []interface{}{ctx, clusterId, params} for _, a := range reqEditors { varargs = append(varargs, a) } @@ -1869,9 +1889,9 @@ func (m *MockClientInterface) ScheduledRebalancingAPIListRebalancingJobs(ctx con } // ScheduledRebalancingAPIListRebalancingJobs indicates an expected call of ScheduledRebalancingAPIListRebalancingJobs. -func (mr *MockClientInterfaceMockRecorder) ScheduledRebalancingAPIListRebalancingJobs(ctx, clusterId interface{}, reqEditors ...interface{}) *gomock.Call { +func (mr *MockClientInterfaceMockRecorder) ScheduledRebalancingAPIListRebalancingJobs(ctx, clusterId, params interface{}, reqEditors ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, clusterId}, reqEditors...) + varargs := append([]interface{}{ctx, clusterId, params}, reqEditors...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduledRebalancingAPIListRebalancingJobs", reflect.TypeOf((*MockClientInterface)(nil).ScheduledRebalancingAPIListRebalancingJobs), varargs...) } @@ -3318,6 +3338,21 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) NodeConfigurationAPIList return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeConfigurationAPIListConfigurationsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).NodeConfigurationAPIListConfigurationsWithResponse), ctx, clusterId) } +// NodeConfigurationAPIListMaxPodsPresetsWithResponse mocks base method. +func (m *MockClientWithResponsesInterface) NodeConfigurationAPIListMaxPodsPresetsWithResponse(ctx context.Context) (*sdk.NodeConfigurationAPIListMaxPodsPresetsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NodeConfigurationAPIListMaxPodsPresetsWithResponse", ctx) + ret0, _ := ret[0].(*sdk.NodeConfigurationAPIListMaxPodsPresetsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NodeConfigurationAPIListMaxPodsPresetsWithResponse indicates an expected call of NodeConfigurationAPIListMaxPodsPresetsWithResponse. +func (mr *MockClientWithResponsesInterfaceMockRecorder) NodeConfigurationAPIListMaxPodsPresetsWithResponse(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeConfigurationAPIListMaxPodsPresetsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).NodeConfigurationAPIListMaxPodsPresetsWithResponse), ctx) +} + // NodeConfigurationAPISetDefaultWithResponse mocks base method. func (m *MockClientWithResponsesInterface) NodeConfigurationAPISetDefaultWithResponse(ctx context.Context, clusterId, id string) (*sdk.NodeConfigurationAPISetDefaultResponse, error) { m.ctrl.T.Helper() @@ -3814,18 +3849,18 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) ScheduledRebalancingAPIL } // ScheduledRebalancingAPIListRebalancingJobsWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string) (*sdk.ScheduledRebalancingAPIListRebalancingJobsResponse, error) { +func (m *MockClientWithResponsesInterface) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx context.Context, clusterId string, params *sdk.ScheduledRebalancingAPIListRebalancingJobsParams) (*sdk.ScheduledRebalancingAPIListRebalancingJobsResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ScheduledRebalancingAPIListRebalancingJobsWithResponse", ctx, clusterId) + ret := m.ctrl.Call(m, "ScheduledRebalancingAPIListRebalancingJobsWithResponse", ctx, clusterId, params) ret0, _ := ret[0].(*sdk.ScheduledRebalancingAPIListRebalancingJobsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // ScheduledRebalancingAPIListRebalancingJobsWithResponse indicates an expected call of ScheduledRebalancingAPIListRebalancingJobsWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx, clusterId interface{}) *gomock.Call { +func (mr *MockClientWithResponsesInterfaceMockRecorder) ScheduledRebalancingAPIListRebalancingJobsWithResponse(ctx, clusterId, params interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduledRebalancingAPIListRebalancingJobsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).ScheduledRebalancingAPIListRebalancingJobsWithResponse), ctx, clusterId) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduledRebalancingAPIListRebalancingJobsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).ScheduledRebalancingAPIListRebalancingJobsWithResponse), ctx, clusterId, params) } // ScheduledRebalancingAPIListRebalancingSchedulesWithResponse mocks base method. diff --git a/examples/gke/gke_cluster_autoscaler_policies/castai.tf b/examples/gke/gke_cluster_autoscaler_policies/castai.tf index c6b648c9..f7d3b00b 100644 --- a/examples/gke/gke_cluster_autoscaler_policies/castai.tf +++ b/examples/gke/gke_cluster_autoscaler_policies/castai.tf @@ -105,12 +105,9 @@ module "castai-gke-cluster" { spot = true use_spot_fallbacks = true min_cpu = 4 - max_cpu = 100 instance_families = { exclude = ["e2"] } - compute_optimized = false - storage_optimized = false # Optional: define custom priority for instances selection. # diff --git a/examples/gke/gke_cluster_autoscaler_policies/version.tf b/examples/gke/gke_cluster_autoscaler_policies/version.tf index 502f0c51..2d0c903a 100644 --- a/examples/gke/gke_cluster_autoscaler_policies/version.tf +++ b/examples/gke/gke_cluster_autoscaler_policies/version.tf @@ -2,6 +2,7 @@ terraform { required_providers { castai = { source = "castai/castai" + version = "0.0.0-local" } kubernetes = { source = "hashicorp/kubernetes"