Skip to content

Commit 8cb0d49

Browse files
committed
minor cleanup
1 parent b82dce7 commit 8cb0d49

File tree

8 files changed

+86
-44
lines changed

8 files changed

+86
-44
lines changed

internal/validation/suite.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,19 @@ type KubernetesValidationOpts struct {
218218
Name string
219219
RefID string
220220
KubernetesVersion string
221+
NodeGroupOpts *KubernetesValidationNodeGroupOpts
221222
NetworkOpts *KubernetesValidationNetworkOpts
222223
}
223224

225+
type KubernetesValidationNodeGroupOpts struct {
226+
Name string
227+
RefID string
228+
MinNodeCount int
229+
MaxNodeCount int
230+
InstanceType string
231+
DiskSizeGiB int
232+
}
233+
224234
type KubernetesValidationNetworkOpts struct {
225235
Name string
226236
RefID string

v1/kubernetes.go

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,6 @@ type DeleteNodeGroupArgs struct {
134134
ID CloudProviderResourceID
135135
}
136136

137-
type CreateNodeGroupResponse struct {
138-
ID CloudProviderResourceID
139-
Name string
140-
RefID string
141-
MinNodeCount int
142-
MaxNodeCount int
143-
InstanceType string
144-
DiskSizeGiB int
145-
}
146-
147137
type DeleteClusterArgs struct {
148138
ID CloudProviderResourceID
149139
}
@@ -152,7 +142,7 @@ type CloudMaintainKubernetes interface {
152142
CreateCluster(ctx context.Context, args CreateClusterArgs) (*Cluster, error)
153143
GetCluster(ctx context.Context, args GetClusterArgs) (*Cluster, error)
154144
PutUser(ctx context.Context, args PutUserArgs) (*PutUserResponse, error)
155-
CreateNodeGroup(ctx context.Context, args CreateNodeGroupArgs) (*CreateNodeGroupResponse, error)
145+
CreateNodeGroup(ctx context.Context, args CreateNodeGroupArgs) (*NodeGroup, error)
156146
GetNodeGroup(ctx context.Context, args GetNodeGroupArgs) (*NodeGroup, error)
157147
ModifyNodeGroup(ctx context.Context, args ModifyNodeGroupArgs) error
158148
DeleteNodeGroup(ctx context.Context, args DeleteNodeGroupArgs) error
@@ -165,6 +155,25 @@ func ValidateCreateKubernetesCluster(ctx context.Context, client CloudMaintainKu
165155
return nil, err
166156
}
167157

158+
if cluster.Name != attrs.Name {
159+
return nil, fmt.Errorf("cluster name does not match create args: '%s' != '%s'", cluster.Name, attrs.Name)
160+
}
161+
if cluster.RefID != attrs.RefID {
162+
return nil, fmt.Errorf("cluster refID does not match create args: '%s' != '%s'", cluster.RefID, attrs.RefID)
163+
}
164+
if cluster.Location != attrs.Location {
165+
return nil, fmt.Errorf("cluster location does not match create args: '%s' != '%s'", cluster.Location, attrs.Location)
166+
}
167+
if cluster.KubernetesVersion != attrs.KubernetesVersion {
168+
return nil, fmt.Errorf("cluster KubernetesVersion does not match create args: '%s' != '%s'", cluster.KubernetesVersion, attrs.KubernetesVersion)
169+
}
170+
if cluster.VPCID != attrs.VPCID {
171+
return nil, fmt.Errorf("cluster VPCID does not match create args: '%s' != '%s'", cluster.VPCID, attrs.VPCID)
172+
}
173+
if len(cluster.SubnetIDs) != len(attrs.SubnetIDs) {
174+
return nil, fmt.Errorf("cluster subnetIDs does not match create args: '%d' != '%d'", len(cluster.SubnetIDs), len(attrs.SubnetIDs))
175+
}
176+
168177
return cluster, nil
169178
}
170179

@@ -173,6 +182,11 @@ func ValidateGetKubernetesCluster(ctx context.Context, client CloudMaintainKuber
173182
if err != nil {
174183
return nil, err
175184
}
185+
186+
if cluster.ID != attrs.ID {
187+
return nil, fmt.Errorf("cluster ID does not match get args: '%s' != '%s'", cluster.ID, attrs.ID)
188+
}
189+
176190
return cluster, nil
177191
}
178192

@@ -223,12 +237,32 @@ func ValidateGetKubernetesClusterCredentials(ctx context.Context, client CloudMa
223237
return putUserResponse, nil
224238
}
225239

226-
func ValidateCreateKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs CreateNodeGroupArgs) error {
227-
_, err := client.CreateNodeGroup(ctx, attrs)
240+
func ValidateCreateKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs CreateNodeGroupArgs) (*NodeGroup, error) {
241+
nodeGroup, err := client.CreateNodeGroup(ctx, attrs)
228242
if err != nil {
229-
return err
243+
return nil, err
230244
}
231-
return nil
245+
246+
if nodeGroup.Name != attrs.Name {
247+
return nil, fmt.Errorf("node group name does not match create args: '%s' != '%s'", nodeGroup.Name, attrs.Name)
248+
}
249+
if nodeGroup.RefID != attrs.RefID {
250+
return nil, fmt.Errorf("node group refID does not match create args: '%s' != '%s'", nodeGroup.RefID, attrs.RefID)
251+
}
252+
if nodeGroup.MinNodeCount != attrs.MinNodeCount {
253+
return nil, fmt.Errorf("node group minNodeCount does not match create args: '%d' != '%d'", nodeGroup.MinNodeCount, attrs.MinNodeCount)
254+
}
255+
if nodeGroup.MaxNodeCount != attrs.MaxNodeCount {
256+
return nil, fmt.Errorf("node group maxNodeCount does not match create args: '%d' != '%d'", nodeGroup.MaxNodeCount, attrs.MaxNodeCount)
257+
}
258+
if nodeGroup.InstanceType != attrs.InstanceType {
259+
return nil, fmt.Errorf("node group instanceType does not match create args: '%s' != '%s'", nodeGroup.InstanceType, attrs.InstanceType)
260+
}
261+
if nodeGroup.DiskSizeGiB != attrs.DiskSizeGiB {
262+
return nil, fmt.Errorf("node group diskSizeGiB does not match create args: '%d' != '%d'", nodeGroup.DiskSizeGiB, attrs.DiskSizeGiB)
263+
}
264+
265+
return nodeGroup, nil
232266
}
233267

234268
func ValidateGetKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs GetNodeGroupArgs) error {

v1/notimplemented.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (c notImplCloudClient) PutUser(_ context.Context, _ PutUserArgs) (*PutUserR
151151
return nil, ErrNotImplemented
152152
}
153153

154-
func (c notImplCloudClient) CreateNodeGroup(_ context.Context, _ CreateNodeGroupArgs) (*CreateNodeGroupResponse, error) {
154+
func (c notImplCloudClient) CreateNodeGroup(_ context.Context, _ CreateNodeGroupArgs) (*NodeGroup, error) {
155155
return nil, ErrNotImplemented
156156
}
157157

v1/providers/aws/kubernetes.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ func createCluster(ctx context.Context, awsClient awsClient, args v1.CreateClust
130130
"CreatedBy": tagBrevCloudSDK,
131131
}
132132

133+
subnetIDs := make([]string, len(args.SubnetIDs))
134+
for i, subnetID := range args.SubnetIDs {
135+
subnetIDs[i] = string(subnetID)
136+
}
133137
input := &eks.CreateClusterInput{
134138
Name: aws.String(args.Name),
135139
Version: aws.String(args.KubernetesVersion),
136140
RoleArn: aws.String(serviceRoleARN),
137141
ResourcesVpcConfig: &ekstypes.VpcConfigRequest{
138-
SubnetIds: args.SubnetIDs,
142+
SubnetIds: subnetIDs,
139143
},
140144
Tags: tags,
141145
}
@@ -204,7 +208,7 @@ func (c *AWSClient) PutUser(_ context.Context, _ v1.PutUserArgs) (*v1.PutUserRes
204208
panic("unimplemented")
205209
}
206210

207-
func (c *AWSClient) CreateNodeGroup(_ context.Context, _ v1.CreateNodeGroupArgs) (*v1.CreateNodeGroupResponse, error) {
211+
func (c *AWSClient) CreateNodeGroup(_ context.Context, _ v1.CreateNodeGroupArgs) (*v1.NodeGroup, error) {
208212
panic("unimplemented")
209213
}
210214

v1/providers/aws/network.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *AWSClient) CreateVPC(ctx context.Context, args v1.CreateVPCArgs) (*v1.V
4141
CloudCredRefID: c.GetReferenceID(),
4242
Provider: CloudProviderID,
4343
Cloud: CloudProviderID,
44-
CloudID: *awsVPC.VpcId,
44+
ID: v1.CloudProviderResourceID(*awsVPC.VpcId),
4545
CidrBlock: *awsVPC.CidrBlock,
4646
Status: v1.VPCStatusAvailable,
4747
}, nil
@@ -571,7 +571,7 @@ func getVPCStatus(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc)
571571
return v1.VPCStatusAvailable, nil
572572
}
573573

574-
func getVPCSubnets(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc) ([]v1.Subnet, error) {
574+
func getVPCSubnets(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc) ([]*v1.Subnet, error) {
575575
describeSubnetsOutput, err := awsClient.DescribeSubnets(ctx, &ec2.DescribeSubnetsInput{
576576
Filters: []types.Filter{
577577
{
@@ -584,7 +584,7 @@ func getVPCSubnets(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc
584584
return nil, err
585585
}
586586

587-
subnets := make([]v1.Subnet, 0)
587+
subnets := make([]*v1.Subnet, 0)
588588
for _, subnet := range describeSubnetsOutput.Subnets {
589589
var subnetType v1.SubnetType
590590

@@ -596,7 +596,7 @@ func getVPCSubnets(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc
596596
}
597597
}
598598

599-
subnets = append(subnets, v1.Subnet{
599+
subnets = append(subnets, &v1.Subnet{
600600
ID: v1.CloudProviderResourceID(*subnet.SubnetId),
601601
VPCID: v1.CloudProviderResourceID(*awsVPC.VpcId),
602602
Location: *subnet.AvailabilityZone,
@@ -610,10 +610,10 @@ func getVPCSubnets(ctx context.Context, awsClient *ec2.Client, awsVPC *types.Vpc
610610
func (c *AWSClient) DeleteVPC(ctx context.Context, args v1.DeleteVPCArgs) error {
611611
// Create the AWS client in the specified region
612612
awsClient := ec2.NewFromConfig(c.awsConfig, func(o *ec2.Options) {
613-
o.Region = args.Location
613+
// o.Region = args.Location
614614
})
615615

616-
err := deleteVPC(ctx, awsClient, args.VPC.CloudID)
616+
err := deleteVPC(ctx, awsClient, string(args.ID))
617617
if err != nil {
618618
return err
619619
}

v1/providers/aws/network_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ func TestDeleteVPC(t *testing.T) {
2020
}
2121

2222
err = awsClient.DeleteVPC(context.Background(), v1.DeleteVPCArgs{
23-
VPC: &v1.VPC{
24-
CloudID: "vpc-0b4e2176e45300c81",
25-
Location: "eu-west-1",
26-
},
23+
ID: v1.CloudProviderResourceID("vpc-0b4e2176e45300c81"),
2724
})
2825
if err != nil {
2926
t.Fatalf("failed to delete VPC: %v", err)
@@ -61,18 +58,15 @@ func TestCreateVPC(t *testing.T) {
6158
}
6259

6360
vpc, err = awsClient.GetVPC(context.Background(), v1.GetVPCArgs{
64-
CloudID: vpc.CloudID,
61+
ID: vpc.ID,
6562
Location: vpc.Location,
6663
})
6764
if err != nil {
6865
t.Fatalf("failed to get VPC: %v", err)
6966
}
7067

7168
err = awsClient.DeleteVPC(context.Background(), v1.DeleteVPCArgs{
72-
VPC: &v1.VPC{
73-
CloudID: vpc.CloudID,
74-
Location: location,
75-
},
69+
ID: vpc.ID,
7670
})
7771
if err != nil {
7872
t.Fatalf("failed to delete VPC: %v", err)

v1/providers/nebius/kubernetes.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,7 @@ func (c *NebiusClient) PutUser(ctx context.Context, args v1.PutUserArgs) (*v1.Pu
264264
}, nil
265265
}
266266

267-
var platformPresetMap = map[string][]string{
268-
"cpu-d3": {"4vcpu-16gb", "8vcpu-32gb", "16vcpu-64gb", "32vcpu-128gb", "48vcpu-192gb", "64vcpu-256gb", "96vcpu-384gb", "128vcpu-512gb"},
269-
"cpu-e2": {"2vcpu-8gb", "4vcpu-16gb", "8vcpu-32gb", "16vcpu-64gb", "32vcpu-128gb", "48vcpu-192gb", "64vcpu-256gb", "80vcpu-320gb"},
270-
"gpu-h200-sxm": {"1gpu-16vcpu-200gb", "8gpu-128vcpu-1600gb"},
271-
"gpu-h100-sxm": {"1gpu-16vcpu-200gb", "8gpu-128vcpu-1600gb"},
272-
"gpu-l40s-a": {"1gpu-8vcpu-32gb", "1gpu-16vcpu-64gb", "1gpu-24vcpu-96gb", "1gpu-32vcpu-128gb", "1gpu-40vcpu-160gb"},
273-
"gpu-l40s-d": {"1gpu-16vcpu-96gb", "1gpu-32vcpu-192gb", "1gpu-48vcpu-288gb", "2gpu-64vcpu-384gb", "2gpu-96vcpu-576gb", "4gpu-128vcpu-768gb", "4gpu-192vcpu-1152gb"},
274-
}
275-
276-
func (c *NebiusClient) CreateNodeGroup(ctx context.Context, args v1.CreateNodeGroupArgs) (*v1.CreateNodeGroupResponse, error) {
267+
func (c *NebiusClient) CreateNodeGroup(ctx context.Context, args v1.CreateNodeGroupArgs) (*v1.NodeGroup, error) {
277268
nebiusNodeGroupService := c.sdk.Services().MK8S().V1().NodeGroup()
278269

279270
// Fetch the cluster the user key will be added to
@@ -334,7 +325,7 @@ func (c *NebiusClient) CreateNodeGroup(ctx context.Context, args v1.CreateNodeGr
334325
return nil, err
335326
}
336327

337-
return &v1.CreateNodeGroupResponse{
328+
return &v1.NodeGroup{
338329
ID: args.ClusterID,
339330
Name: args.Name,
340331
RefID: args.RefID,

v1/providers/nebius/kubernetes_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import (
99
v1 "github.com/brevdev/cloud/v1"
1010
)
1111

12+
var platformPresetMap = map[string][]string{
13+
"cpu-d3": {"4vcpu-16gb", "8vcpu-32gb", "16vcpu-64gb", "32vcpu-128gb", "48vcpu-192gb", "64vcpu-256gb", "96vcpu-384gb", "128vcpu-512gb"},
14+
"cpu-e2": {"2vcpu-8gb", "4vcpu-16gb", "8vcpu-32gb", "16vcpu-64gb", "32vcpu-128gb", "48vcpu-192gb", "64vcpu-256gb", "80vcpu-320gb"},
15+
"gpu-h200-sxm": {"1gpu-16vcpu-200gb", "8gpu-128vcpu-1600gb"},
16+
"gpu-h100-sxm": {"1gpu-16vcpu-200gb", "8gpu-128vcpu-1600gb"},
17+
"gpu-l40s-a": {"1gpu-8vcpu-32gb", "1gpu-16vcpu-64gb", "1gpu-24vcpu-96gb", "1gpu-32vcpu-128gb", "1gpu-40vcpu-160gb"},
18+
"gpu-l40s-d": {"1gpu-16vcpu-96gb", "1gpu-32vcpu-192gb", "1gpu-48vcpu-288gb", "2gpu-64vcpu-384gb", "2gpu-96vcpu-576gb", "4gpu-128vcpu-768gb", "4gpu-192vcpu-1152gb"},
19+
}
20+
1221
func Test_CreateVPCAndCluster(t *testing.T) {
1322
privateKeyPEMBase64 := os.Getenv("NEBIUS_PRIVATE_KEY_PEM_BASE64")
1423
publicKeyID := os.Getenv("NEBIUS_PUBLIC_KEY_ID")

0 commit comments

Comments
 (0)