Skip to content

Commit

Permalink
chore: SDK API client improvements (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtwardowski authored Jan 14, 2025
1 parent 0152881 commit e014225
Show file tree
Hide file tree
Showing 14 changed files with 4,101 additions and 47 deletions.
6 changes: 3 additions & 3 deletions castai/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func resourceCastaiClusterDelete(ctx context.Context, data *schema.ResourceData,
return nil
}

func fetchClusterData(ctx context.Context, client *sdk.ClientWithResponses, clusterID string) (*sdk.ExternalClusterAPIGetClusterResponse, error) {
func fetchClusterData(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterID string) (*sdk.ExternalClusterAPIGetClusterResponse, error) {
resp, err := client.ExternalClusterAPIGetClusterWithResponse(ctx, clusterID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -140,7 +140,7 @@ func fetchClusterData(ctx context.Context, client *sdk.ClientWithResponses, clus
// Caller is responsible to populate data and request parameters with all data.
func resourceCastaiClusterUpdate(
ctx context.Context,
client *sdk.ClientWithResponses,
client sdk.ClientWithResponsesInterface,
data *schema.ResourceData,
request *sdk.ExternalClusterAPIUpdateClusterJSONRequestBody,
) error {
Expand Down Expand Up @@ -206,7 +206,7 @@ func resourceCastaiClusterUpdate(
return nil
}

func createClusterToken(ctx context.Context, client *sdk.ClientWithResponses, clusterID string) (string, error) {
func createClusterToken(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterID string) (string, error) {
resp, err := client.ExternalClusterAPICreateClusterTokenWithResponse(ctx, clusterID)
if err != nil {
return "", fmt.Errorf("creating cluster token: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion castai/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type ProviderConfig struct {
api *sdk.ClientWithResponses
api sdk.ClientWithResponsesInterface
}

func Provider(version string) *schema.Provider {
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_aks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func resourceCastaiAKSClusterUpdate(ctx context.Context, data *schema.ResourceDa
return resourceCastaiAKSClusterRead(ctx, data, meta)
}

func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, client *sdk.ClientWithResponses) error {
func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, client sdk.ClientWithResponsesInterface) error {
if !data.HasChanges(
FieldAKSClusterClientID,
FieldAKSClusterClientSecret,
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func resourceCastaiAutoscalerUpdate(ctx context.Context, data *schema.ResourceDa
return nil
}

func getCurrentPolicies(ctx context.Context, client *sdk.ClientWithResponses, clusterId string) ([]byte, error) {
func getCurrentPolicies(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterId string) ([]byte, error) {
log.Printf("[INFO] Getting cluster autoscaler information.")

resp, err := client.PoliciesAPIGetClusterPolicies(ctx, clusterId)
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_eks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func resourceCastaiEKSClusterUpdate(ctx context.Context, data *schema.ResourceDa
return resourceCastaiEKSClusterRead(ctx, data, meta)
}

func updateClusterSettings(ctx context.Context, data *schema.ResourceData, client *sdk.ClientWithResponses) error {
func updateClusterSettings(ctx context.Context, data *schema.ResourceData, client sdk.ClientWithResponsesInterface) error {
if !data.HasChanges(
FieldEKSClusterAssumeRoleArn,
FieldClusterCredentialsId,
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_gke_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func resourceCastaiGKEClusterUpdate(ctx context.Context, data *schema.ResourceDa
return resourceCastaiGKEClusterRead(ctx, data, meta)
}

func updateGKEClusterSettings(ctx context.Context, data *schema.ResourceData, client *sdk.ClientWithResponses) error {
func updateGKEClusterSettings(ctx context.Context, data *schema.ResourceData, client sdk.ClientWithResponsesInterface) error {
if !data.HasChanges(
FieldGKEClusterCredentials,
FieldClusterCredentialsId,
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_organization_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func resourceOrganizationGroupDelete(ctx context.Context, data *schema.ResourceD
return nil
}

func getGroup(client *sdk.ClientWithResponses, ctx context.Context, organizationID, groupID string) (*sdk.CastaiRbacV1beta1Group, error) {
func getGroup(client sdk.ClientWithResponsesInterface, ctx context.Context, organizationID, groupID string) (*sdk.CastaiRbacV1beta1Group, error) {
groupsResp, err := client.RbacServiceAPIGetGroupWithResponse(ctx, organizationID, groupID)
if err != nil {
return nil, fmt.Errorf("fetching group: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions castai/resource_rebalancing_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func rebalancingJobToState(job *sdk.ScheduledrebalancingV1RebalancingJob, d *sch
return nil
}

func getRebalancingJobByScheduleName(ctx context.Context, client *sdk.ClientWithResponses, clusterID string, scheduleName string) (*sdk.ScheduledrebalancingV1RebalancingJob, error) {
func getRebalancingJobByScheduleName(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterID string, scheduleName string) (*sdk.ScheduledrebalancingV1RebalancingJob, error) {
schedule, err := getRebalancingScheduleByName(ctx, client, scheduleName)
if err != nil {
return nil, fmt.Errorf("getting schedule: %w", err)
Expand Down Expand Up @@ -234,7 +234,7 @@ func getRebalancingJobByScheduleName(ctx context.Context, client *sdk.ClientWith
return nil, fmt.Errorf("rebalancing job for schedule %q was not found", scheduleName)
}

func getRebalancingJobById(ctx context.Context, client *sdk.ClientWithResponses, clusterID string, id string) (*sdk.ScheduledrebalancingV1RebalancingJob, bool, error) {
func getRebalancingJobById(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterID string, id string) (*sdk.ScheduledrebalancingV1RebalancingJob, bool, error) {
resp, err := client.ScheduledRebalancingAPIGetRebalancingJobWithResponse(ctx, clusterID, id)
if err != nil {
return nil, false, err
Expand All @@ -249,7 +249,7 @@ func getRebalancingJobById(ctx context.Context, client *sdk.ClientWithResponses,
return resp.JSON200, true, nil
}

func getRebalancingJobByScheduleId(ctx context.Context, client *sdk.ClientWithResponses, clusterID, scheduleID string) (*sdk.ScheduledrebalancingV1RebalancingJob, bool, error) {
func getRebalancingJobByScheduleId(ctx context.Context, client sdk.ClientWithResponsesInterface, clusterID, scheduleID string) (*sdk.ScheduledrebalancingV1RebalancingJob, bool, error) {
params := &sdk.ScheduledRebalancingAPIListRebalancingJobsParams{
RebalancingScheduleId: lo.ToPtr(scheduleID),
}
Expand Down
4 changes: 2 additions & 2 deletions castai/resource_rebalancing_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func nullifySelectorRequirements(requirements *[]sdk.ScheduledrebalancingV1NodeS
}
}

func getRebalancingScheduleByName(ctx context.Context, client *sdk.ClientWithResponses, name string) (*sdk.ScheduledrebalancingV1RebalancingSchedule, error) {
func getRebalancingScheduleByName(ctx context.Context, client sdk.ClientWithResponsesInterface, name string) (*sdk.ScheduledrebalancingV1RebalancingSchedule, error) {
resp, err := client.ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx)
if checkErr := sdk.CheckOKResponse(resp, err); checkErr != nil {
return nil, checkErr
Expand All @@ -424,7 +424,7 @@ func getRebalancingScheduleByName(ctx context.Context, client *sdk.ClientWithRes
return nil, fmt.Errorf("rebalancing schedule %q was not found", name)
}

func getRebalancingScheduleById(ctx context.Context, client *sdk.ClientWithResponses, id string) (*sdk.ScheduledrebalancingV1RebalancingSchedule, error) {
func getRebalancingScheduleById(ctx context.Context, client sdk.ClientWithResponsesInterface, id string) (*sdk.ScheduledrebalancingV1RebalancingSchedule, error) {
resp, err := client.ScheduledRebalancingAPIGetRebalancingScheduleWithResponse(ctx, id)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_role_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func resourceRoleBindingsDelete(ctx context.Context, data *schema.ResourceData,
return nil
}

func getRoleBinding(client *sdk.ClientWithResponses, ctx context.Context, organizationID, roleBindingID string) (*sdk.CastaiRbacV1beta1RoleBinding, error) {
func getRoleBinding(client sdk.ClientWithResponsesInterface, ctx context.Context, organizationID, roleBindingID string) (*sdk.CastaiRbacV1beta1RoleBinding, error) {
resp, err := client.RbacServiceAPIGetRoleBindingWithResponse(ctx, organizationID, roleBindingID)
if err != nil {
return nil, fmt.Errorf("fetching role binding: %w", err)
Expand Down
14 changes: 13 additions & 1 deletion castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions castai/sdk/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions castai/sdk/codegen/templates/client-with-responses.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func WithBaseURL(baseURL string) ClientOption {

// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
ClientInterface
{{range . -}}
{{$hasParams := .RequiresParamObject -}}
{{$pathParams := .PathParams -}}
Expand Down
Loading

0 comments on commit e014225

Please sign in to comment.