From 160cb83119d421f6d86f65d8709c52998c013ee5 Mon Sep 17 00:00:00 2001 From: gleb Date: Thu, 28 Mar 2024 13:23:06 +0100 Subject: [PATCH] add sdk --- castai/sdk/api.gen.go | 59 +++++++++++++++----- castai/sdk/client.gen.go | 117 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 14 deletions(-) diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index a2b994e2e..418838232 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -1581,7 +1581,8 @@ type NodeconfigV1EKSConfig struct { KeyPairId *string `json:"keyPairId"` // Cluster's security groups configuration. - SecurityGroups *[]string `json:"securityGroups,omitempty"` + SecurityGroups *[]string `json:"securityGroups,omitempty"` + TargetGroup *NodeconfigV1TargetGroup `json:"targetGroup,omitempty"` // EBS volume IOPS value to be used for provisioned nodes. VolumeIops *int32 `json:"volumeIops"` @@ -1818,6 +1819,15 @@ type NodeconfigV1SubnetDetails_Tags struct { AdditionalProperties map[string]string `json:"-"` } +// NodeconfigV1TargetGroup defines model for nodeconfig.v1.TargetGroup. +type NodeconfigV1TargetGroup struct { + // ARN of the target group. + Arn *string `json:"arn,omitempty"` + + // Port of the target group. + Port *int32 `json:"port"` +} + // NodetemplatesV1AvailableInstanceType defines model for nodetemplates.v1.AvailableInstanceType. type NodetemplatesV1AvailableInstanceType struct { Architecture *string `json:"architecture,omitempty"` @@ -1854,6 +1864,11 @@ type NodetemplatesV1FilterInstanceTypesResponse struct { AvailableInstanceTypes *[]NodetemplatesV1AvailableInstanceType `json:"availableInstanceTypes,omitempty"` } +// NodetemplatesV1GenerateNodeTemplatesResponse defines model for nodetemplates.v1.GenerateNodeTemplatesResponse. +type NodetemplatesV1GenerateNodeTemplatesResponse struct { + Items *[]NodetemplatesV1NodeTemplateListItem `json:"items,omitempty"` +} + // NodetemplatesV1Label defines model for nodetemplates.v1.Label. type NodetemplatesV1Label struct { Key *string `json:"key,omitempty"` @@ -1982,6 +1997,23 @@ type NodetemplatesV1TemplateConstraints struct { // Custom sorting priority - instances matching defined rules will take priority over other candidates. CustomPriority *[]NodetemplatesV1TemplateConstraintsCustomPriority `json:"customPriority,omitempty"` + // Dedicated node affinity - creates preference for instances to be created on sole tenancy or dedicated nodes. + // + // Dedicated node affinity - creates preference for instances to be created on sole tenancy or dedicated nodes. This + // feature is only available for GCP clusters and sole tenancy nodes with local SSDs or GPUs are not supported. If + // the sole tenancy or dedicated nodes don't have capacity for selected instance type, the Autoscaler will fall back + // to multi-tenant instance types available for this Node Template. Other instance constraints are applied when + // the Autoscaler picks available instance types that can be created on the sole tenancy or dedicated + // node (example: setting min CPU to 16). + // + // When using dedicated node affinity, with a shared sole tenancy node group in GCP following rules and limitations apply: + // - Use Resource URI/FQDN of the sole tenancy node group as the name (example: /projects/test-123/zones/europe-west1b/nodeGroups/test-node-group). + // - The GKE cluster must use Shared VPC (https://cloud.google.com/vpc/docs/shared-vpc). + // - The sole tenancy node group must be shared with the GKE cluster's project or organization. + // - The CAST's service account must have the necessary permissions to create and operate instances + // on the sole tenancy node group's project. + DedicatedNodeAffinity *[]NodetemplatesV1TemplateConstraintsDedicatedNodeAffinity `json:"dedicatedNodeAffinity,omitempty"` + // Enable/disable spot diversity policy. When enabled, autoscaler will try to balance between diverse and cost optimal instance types. EnableSpotDiversity *bool `json:"enableSpotDiversity"` @@ -1992,12 +2024,11 @@ type NodetemplatesV1TemplateConstraints struct { // This template is gpu only. Setting this to true, will result in only instances with GPUs being considered. // In addition, this ensures that all of the added instances for this template won't have any nvidia taints. - IsGpuOnly *bool `json:"isGpuOnly"` - MaxCpu *int32 `json:"maxCpu"` - MaxMemory *int32 `json:"maxMemory"` - MinCpu *int32 `json:"minCpu"` - MinMemory *int32 `json:"minMemory"` - NodeAffinity *[]NodetemplatesV1TemplateConstraintsNodeAffinity `json:"nodeAffinity,omitempty"` + IsGpuOnly *bool `json:"isGpuOnly"` + MaxCpu *int32 `json:"maxCpu"` + MaxMemory *int32 `json:"maxMemory"` + MinCpu *int32 `json:"minCpu"` + MinMemory *int32 `json:"minMemory"` // Should include on-demand instances in the considered pool. OnDemand *bool `json:"onDemand"` @@ -2037,6 +2068,13 @@ type NodetemplatesV1TemplateConstraintsCustomPriority struct { Spot *bool `json:"spot"` } +// 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"` +} + // NodetemplatesV1TemplateConstraintsGPUConstraints defines model for nodetemplates.v1.TemplateConstraints.GPUConstraints. type NodetemplatesV1TemplateConstraintsGPUConstraints struct { ExcludeNames *[]string `json:"excludeNames,omitempty"` @@ -2052,13 +2090,6 @@ type NodetemplatesV1TemplateConstraintsInstanceFamilyConstraints struct { Include *[]string `json:"include,omitempty"` } -// NodetemplatesV1TemplateConstraintsNodeAffinity defines model for nodetemplates.v1.TemplateConstraints.NodeAffinity. -type NodetemplatesV1TemplateConstraintsNodeAffinity struct { - AzName *string `json:"azName,omitempty"` - InstanceTypes *[]string `json:"instanceTypes,omitempty"` - Name *string `json:"name,omitempty"` -} - // NodetemplatesV1UpdateNodeTemplate defines model for nodetemplates.v1.UpdateNodeTemplate. type NodetemplatesV1UpdateNodeTemplate struct { ConfigurationId *string `json:"configurationId,omitempty"` diff --git a/castai/sdk/client.gen.go b/castai/sdk/client.gen.go index 33a1c432f..c6595b3a9 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -138,6 +138,9 @@ type ClientInterface interface { NodeTemplatesAPIFilterInstanceTypes(ctx context.Context, clusterId string, body NodeTemplatesAPIFilterInstanceTypesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // NodeTemplatesAPIGenerateNodeTemplates request + NodeTemplatesAPIGenerateNodeTemplates(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) + // NodeConfigurationAPIListConfigurations request NodeConfigurationAPIListConfigurations(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -629,6 +632,18 @@ func (c *Client) NodeTemplatesAPIFilterInstanceTypes(ctx context.Context, cluste return c.Client.Do(req) } +func (c *Client) NodeTemplatesAPIGenerateNodeTemplates(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewNodeTemplatesAPIGenerateNodeTemplatesRequest(c.Server, clusterId) + 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) NodeConfigurationAPIListConfigurations(ctx context.Context, clusterId string, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewNodeConfigurationAPIListConfigurationsRequest(c.Server, clusterId) if err != nil { @@ -2343,6 +2358,40 @@ func NewNodeTemplatesAPIFilterInstanceTypesRequestWithBody(server string, cluste return req, nil } +// NewNodeTemplatesAPIGenerateNodeTemplatesRequest generates requests for NodeTemplatesAPIGenerateNodeTemplates +func NewNodeTemplatesAPIGenerateNodeTemplatesRequest(server string, clusterId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "clusterId", runtime.ParamLocationPath, clusterId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/kubernetes/clusters/%s/generate-node-templates", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewNodeConfigurationAPIListConfigurationsRequest generates requests for NodeConfigurationAPIListConfigurations func NewNodeConfigurationAPIListConfigurationsRequest(server string, clusterId string) (*http.Request, error) { var err error @@ -5522,6 +5571,9 @@ type ClientWithResponsesInterface interface { NodeTemplatesAPIFilterInstanceTypesWithResponse(ctx context.Context, clusterId string, body NodeTemplatesAPIFilterInstanceTypesJSONRequestBody) (*NodeTemplatesAPIFilterInstanceTypesResponse, error) + // NodeTemplatesAPIGenerateNodeTemplates request + NodeTemplatesAPIGenerateNodeTemplatesWithResponse(ctx context.Context, clusterId string) (*NodeTemplatesAPIGenerateNodeTemplatesResponse, error) + // NodeConfigurationAPIListConfigurations request NodeConfigurationAPIListConfigurationsWithResponse(ctx context.Context, clusterId string) (*NodeConfigurationAPIListConfigurationsResponse, error) @@ -6166,6 +6218,36 @@ func (r NodeTemplatesAPIFilterInstanceTypesResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 +type NodeTemplatesAPIGenerateNodeTemplatesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *NodetemplatesV1GenerateNodeTemplatesResponse +} + +// Status returns HTTPResponse.Status +func (r NodeTemplatesAPIGenerateNodeTemplatesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r NodeTemplatesAPIGenerateNodeTemplatesResponse) 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 NodeTemplatesAPIGenerateNodeTemplatesResponse) GetBody() []byte { + return r.Body +} + +// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 + type NodeConfigurationAPIListConfigurationsResponse struct { Body []byte HTTPResponse *http.Response @@ -8539,6 +8621,15 @@ func (c *ClientWithResponses) NodeTemplatesAPIFilterInstanceTypesWithResponse(ct return ParseNodeTemplatesAPIFilterInstanceTypesResponse(rsp) } +// NodeTemplatesAPIGenerateNodeTemplatesWithResponse request returning *NodeTemplatesAPIGenerateNodeTemplatesResponse +func (c *ClientWithResponses) NodeTemplatesAPIGenerateNodeTemplatesWithResponse(ctx context.Context, clusterId string) (*NodeTemplatesAPIGenerateNodeTemplatesResponse, error) { + rsp, err := c.NodeTemplatesAPIGenerateNodeTemplates(ctx, clusterId) + if err != nil { + return nil, err + } + return ParseNodeTemplatesAPIGenerateNodeTemplatesResponse(rsp) +} + // NodeConfigurationAPIListConfigurationsWithResponse request returning *NodeConfigurationAPIListConfigurationsResponse func (c *ClientWithResponses) NodeConfigurationAPIListConfigurationsWithResponse(ctx context.Context, clusterId string) (*NodeConfigurationAPIListConfigurationsResponse, error) { rsp, err := c.NodeConfigurationAPIListConfigurations(ctx, clusterId) @@ -9725,6 +9816,32 @@ func ParseNodeTemplatesAPIFilterInstanceTypesResponse(rsp *http.Response) (*Node return response, nil } +// ParseNodeTemplatesAPIGenerateNodeTemplatesResponse parses an HTTP response from a NodeTemplatesAPIGenerateNodeTemplatesWithResponse call +func ParseNodeTemplatesAPIGenerateNodeTemplatesResponse(rsp *http.Response) (*NodeTemplatesAPIGenerateNodeTemplatesResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer rsp.Body.Close() + if err != nil { + return nil, err + } + + response := &NodeTemplatesAPIGenerateNodeTemplatesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest NodetemplatesV1GenerateNodeTemplatesResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseNodeConfigurationAPIListConfigurationsResponse parses an HTTP response from a NodeConfigurationAPIListConfigurationsWithResponse call func ParseNodeConfigurationAPIListConfigurationsResponse(rsp *http.Response) (*NodeConfigurationAPIListConfigurationsResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body)