Skip to content

Commit

Permalink
feat: add throughput tier validation call
Browse files Browse the repository at this point in the history
Adds support, mocks and testing for calling the API to get the valid tiers as part of the throughput_tier validation process
  • Loading branch information
gene-redpanda committed Sep 11, 2024
1 parent bc2591c commit 62c3c75
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 221 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/redpanda-data/terraform-provider-redpanda
go 1.22.4

require (
buf.build/gen/go/redpandadata/cloud/grpc/go v1.4.0-20240715174738-f694d610cde4.2
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240715174738-f694d610cde4.2
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.4.0-20240620104934-3415ce922cfb.2
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240620104934-3415ce922cfb.2
buf.build/gen/go/redpandadata/cloud/grpc/go v1.5.1-20240820164511-1d38ab631312.1
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240820164511-1d38ab631312.2
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.5.1-20240823133854-b83c57715214.1
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240823133854-b83c57715214.2
github.com/davecgh/go-spew v1.1.1
github.com/golang/mock v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-2024050820065
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240508200655-46a4cf4ba109.2/go.mod h1:ylS4c28ACSI59oJrOdW4pHS4n0Hw4TgSPHn8rpHl4Yw=
buf.build/gen/go/grpc-ecosystem/grpc-gateway/protocolbuffers/go v1.34.2-20240617172850-a48fcebcf8f1.2 h1:60531IScGBBw17MoVfvCasfBedurjQ4qkr0cNhrDTR0=
buf.build/gen/go/grpc-ecosystem/grpc-gateway/protocolbuffers/go v1.34.2-20240617172850-a48fcebcf8f1.2/go.mod h1:WZzeH4Sx52g5HpdqDE4B6I0cn5MPzKmp7lSG6oB6ais=
buf.build/gen/go/redpandadata/cloud/grpc/go v1.4.0-20240715174738-f694d610cde4.2 h1:0c9chqpWt8kVI/xIT3RDOsGb1YV3dh1scSQ7c6my1Ug=
buf.build/gen/go/redpandadata/cloud/grpc/go v1.4.0-20240715174738-f694d610cde4.2/go.mod h1:XyOUztl5DY9mqZZKAjV0S/fZ3WPky4oJOAba/LslMeY=
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240715174738-f694d610cde4.2 h1:1RS42QWCLmosvuEvr9wIX1P5H898jPAruOC2eFGTc+I=
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240715174738-f694d610cde4.2/go.mod h1:FYKJ74J6GISLCL3PrEGYtqFhl86Sav4N07klNQSkdX8=
buf.build/gen/go/redpandadata/cloud/grpc/go v1.5.1-20240820164511-1d38ab631312.1 h1:EaObGs198lfRFqiJYXv6ZdOSCeYGLYEUe1rPA8pWOLs=
buf.build/gen/go/redpandadata/cloud/grpc/go v1.5.1-20240820164511-1d38ab631312.1/go.mod h1:QGa6AeVmYRmX2VB5Uz5sqNtNoYprweFTuJeTx6n1Ajw=
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240820164511-1d38ab631312.2 h1:/7EPKwIkk/2tGcD8WnGFTIppsMKE+tMRiw8/SbsPWUA=
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.34.2-20240820164511-1d38ab631312.2/go.mod h1:FYKJ74J6GISLCL3PrEGYtqFhl86Sav4N07klNQSkdX8=
buf.build/gen/go/redpandadata/common/protocolbuffers/go v1.34.2-20240715174743-9c0afe867874.2 h1:mwz77izDe41jrNZqQx2iEzOt4k7pfWthVFuK2SMwCCw=
buf.build/gen/go/redpandadata/common/protocolbuffers/go v1.34.2-20240715174743-9c0afe867874.2/go.mod h1:wThyg02xJx4K/DA5fg0QlKts8XVPyTT86JC8hPfEzno=
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.4.0-20240620104934-3415ce922cfb.2 h1:i3O66JNfIk+0t+NYiFdMSfEmms7G23x56/n/RuljoHE=
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.4.0-20240620104934-3415ce922cfb.2/go.mod h1:PB9dfr839mRnbD7/O+h0v3qOm4STH8zGJIqAAHH2YNE=
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240620104934-3415ce922cfb.2 h1:Zztd29tww+/5N9Ff1HIVYXw+NDsdziaZ11Zg7MQjebc=
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240620104934-3415ce922cfb.2/go.mod h1:AcLjVYZHtwlZvBrjuqyjtZtHv9BbDaHD6C92lO/gJFI=
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.5.1-20240823133854-b83c57715214.1 h1:hYKhjbTC9nkqss9dDYBsnxvBt3Dor8r6oLAFEGX6t9k=
buf.build/gen/go/redpandadata/dataplane/grpc/go v1.5.1-20240823133854-b83c57715214.1/go.mod h1:rsf9MRzxX/cp7vJjPsjRnT2RgLoFbdsle84vAx/P3T0=
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240823133854-b83c57715214.2 h1:3ZtFDLo1aAarCu46YtBmWZciwfR4Vu/TPcI0XFfyEsE=
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.34.2-20240823133854-b83c57715214.2/go.mod h1:AcLjVYZHtwlZvBrjuqyjtZtHv9BbDaHD6C92lO/gJFI=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
Expand Down
2 changes: 2 additions & 0 deletions redpanda/cloud/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ControlPlaneClientSet struct {
Cluster controlplanev1beta2grpc.ClusterServiceClient
ServerlessCluster controlplanev1beta2grpc.ServerlessClusterServiceClient
Operation controlplanev1beta2grpc.OperationServiceClient
ThroughputTier controlplanev1beta2grpc.ThroughputTierServiceClient
}

// NewControlPlaneClientSet uses the passed grpc connection to create a control
Expand All @@ -57,6 +58,7 @@ func NewControlPlaneClientSet(conn *grpc.ClientConn) *ControlPlaneClientSet {
Cluster: controlplanev1beta2grpc.NewClusterServiceClient(conn),
ServerlessCluster: controlplanev1beta2grpc.NewServerlessClusterServiceClient(conn),
Operation: controlplanev1beta2grpc.NewOperationServiceClient(conn),
ThroughputTier: controlplanev1beta2grpc.NewThroughputTierServiceClient(conn),
}
}

Expand Down
77 changes: 77 additions & 0 deletions redpanda/mocks/mock_throughput_service_client.go

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

57 changes: 57 additions & 0 deletions redpanda/mocks/mock_throughput_tier_client.go

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

2 changes: 2 additions & 0 deletions redpanda/mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ package mocks
//go:generate mockgen -destination=./mock_user_service_client.go -package=mocks buf.build/gen/go/redpandadata/dataplane/grpc/go/redpanda/api/dataplane/v1alpha2/dataplanev1alpha2grpc UserServiceClient
//go:generate mockgen -destination=./mock_operations_service_client.go -package=mocks buf.build/gen/go/redpandadata/cloud/grpc/go/redpanda/api/controlplane/v1beta2/controlplanev1beta2grpc OperationServiceClient
//go:generate mockgen -destination=./mock_serverless_cluster_service_client.go -package=mocks buf.build/gen/go/redpandadata/cloud/grpc/go/redpanda/api/controlplane/v1beta2/controlplanev1beta2grpc ServerlessClusterServiceClient
//go:generate mockgen -destination=./mock_throughput_service_client.go -package=mocks buf.build/gen/go/redpandadata/cloud/grpc/go/redpanda/api/controlplane/v1beta2/controlplanev1beta2grpc ThroughputTierServiceClient
//go:generate mockgen -destination=./mock_cp_client_set.go -package=mocks github.com/redpanda-data/terraform-provider-redpanda/redpanda/cloud CpClientSet
//go:generate mockgen -destination=./mock_throughput_tier_client.go -package=mocks github.com/redpanda-data/terraform-provider-redpanda/redpanda/utils ThroughputTierClient
44 changes: 43 additions & 1 deletion redpanda/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strings"
"time"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
rpknet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net"
"github.com/redpanda-data/terraform-provider-redpanda/redpanda/cloud"
"google.golang.org/grpc"
)

const providerUnspecified = "unspecified"
Expand Down Expand Up @@ -311,7 +313,15 @@ func MapToSetTopicConfiguration(cfg types.Map) ([]*dataplanev1alpha2.SetTopicCon
// NumberToInt32 converts a types.Number to an *int32
func NumberToInt32(n types.Number) *int32 {
i, _ := n.ValueBigFloat().Int64()
i32 := int32(i)
var i32 int32
switch {
case i > math.MaxInt32:
i32 = math.MaxInt32
case i < math.MinInt32:
i32 = math.MinInt32
default:
i32 = int32(i)
}
return &i32
}

Expand Down Expand Up @@ -400,3 +410,35 @@ func TypeMapToStringMap(tags types.Map) map[string]string {
}
return tagsMap
}

// ThroughputTierClient is an interface for the ListThroughputTiers method from the controlplanev1beta2 API ThroughputTierServiceClient
type ThroughputTierClient interface {
ListThroughputTiers(ctx context.Context, in *controlplanev1beta2.ListThroughputTiersRequest, opts ...grpc.CallOption) (*controlplanev1beta2.ListThroughputTiersResponse, error)
}

// GetThroughputTiers returns the throughput tiers for the given cloud provider, cluster type, and region
func GetThroughputTiers(ctx context.Context, tt ThroughputTierClient, cloudProvider, clusterType, region string) ([]*controlplanev1beta2.ThroughputTier, error) {
cp, err := StringToCloudProvider(cloudProvider)
if err != nil {
return nil, err
}

ct, err := StringToClusterType(clusterType)
if err != nil {
return nil, err
}

resp, err := tt.ListThroughputTiers(ctx,
&controlplanev1beta2.ListThroughputTiersRequest{
Filter: &controlplanev1beta2.ListThroughputTiersRequest_Filter{
CloudProvider: cp,
ClusterType: ct,
Region: region,
},
},
)
if err != nil {
return nil, err
}
return resp.GetThroughputTiers(), nil
}
Loading

0 comments on commit 62c3c75

Please sign in to comment.