Skip to content

Commit c27a80a

Browse files
committed
save
1 parent bd41c40 commit c27a80a

13 files changed

Lines changed: 443 additions & 126 deletions

internal/validation/suite.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,111 @@ func RunInstanceLifecycleValidation(t *testing.T, config ProviderConfig) {
126126
})
127127
})
128128
}
129+
130+
func RunNetworkValidation(t *testing.T, config ProviderConfig) {
131+
if testing.Short() {
132+
t.Skip("Skipping validation tests in short mode")
133+
}
134+
135+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
136+
defer cancel()
137+
138+
client, err := config.Credential.MakeClient(ctx, config.Location)
139+
if err != nil {
140+
t.Fatalf("Failed to create client for %s: %v", config.Credential.GetCloudProviderID(), err)
141+
}
142+
143+
t.Run("ValidateCreateVPC", func(t *testing.T) {
144+
err := v1.ValidateCreateVPC(ctx, client, v1.CreateVPCArgs{
145+
Name: "test-vpc",
146+
RefID: "test-vpc",
147+
Location: "test-location",
148+
CidrBlock: "172.16.0.0/16",
149+
Subnets: []v1.CreateSubnetArgs{
150+
{CidrBlock: "172.16.0.0/24", Type: v1.SubnetTypePublic},
151+
},
152+
})
153+
require.NoError(t, err, "ValidateCreateVPC should pass")
154+
})
155+
156+
t.Run("ValidateGetVPC", func(t *testing.T) {
157+
err := v1.ValidateGetVPC(ctx, client, v1.GetVPCArgs{
158+
ID: v1.CloudProviderResourceID("test-vpc"),
159+
})
160+
require.NoError(t, err, "ValidateGetVPC should pass")
161+
})
162+
163+
t.Run("ValidateDeleteVPC", func(t *testing.T) {
164+
err := v1.ValidateDeleteVPC(ctx, client, v1.DeleteVPCArgs{
165+
ID: v1.CloudProviderResourceID("test-vpc"),
166+
})
167+
require.NoError(t, err, "ValidateDeleteVPC should pass")
168+
})
169+
}
170+
171+
func RunKubernetesValidation(t *testing.T, config ProviderConfig) {
172+
if testing.Short() {
173+
t.Skip("Skipping validation tests in short mode")
174+
}
175+
176+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
177+
defer cancel()
178+
179+
client, err := config.Credential.MakeClient(ctx, config.Location)
180+
if err != nil {
181+
t.Fatalf("Failed to create client for %s: %v", config.Credential.GetCloudProviderID(), err)
182+
}
183+
184+
t.Run("ValidateCreateKubernetesCluster", func(t *testing.T) {
185+
err := v1.ValidateCreateKubernetesCluster(ctx, client, v1.CreateClusterArgs{
186+
Name: "test-cluster",
187+
RefID: "test-cluster",
188+
VPCID: "test-vpc",
189+
SubnetIDs: []string{"test-subnet"},
190+
KubernetesVersion: "1.24",
191+
Location: "test-location",
192+
})
193+
require.NoError(t, err, "ValidateCreateKubernetesCluster should pass")
194+
})
195+
196+
t.Run("ValidateGetKubernetesCluster", func(t *testing.T) {
197+
err := v1.ValidateGetKubernetesCluster(ctx, client, v1.GetClusterArgs{
198+
ID: v1.CloudProviderResourceID("test-cluster"),
199+
})
200+
require.NoError(t, err, "ValidateGetKubernetesCluster should pass")
201+
})
202+
203+
t.Run("ValidateGetKubernetesClusterCredentials", func(t *testing.T) {
204+
err := v1.ValidateGetKubernetesClusterCredentials(ctx, client, v1.GetClusterArgs{
205+
ID: v1.CloudProviderResourceID("test-cluster"),
206+
})
207+
require.NoError(t, err, "ValidateGetKubernetesClusterCredentials should pass")
208+
})
209+
210+
t.Run("ValidateCreateKubernetesNodeGroup", func(t *testing.T) {
211+
err := v1.ValidateCreateKubernetesNodeGroup(ctx, client, v1.CreateNodeGroupArgs{
212+
ClusterID: v1.CloudProviderResourceID("test-cluster"),
213+
Name: "test-node-group",
214+
RefID: "test-node-group",
215+
MinNodeCount: 1,
216+
MaxNodeCount: 1,
217+
InstanceType: "test-instance-type",
218+
DiskSizeGiB: 100,
219+
})
220+
require.NoError(t, err, "ValidateCreateKubernetesNodeGroup should pass")
221+
})
222+
223+
t.Run("ValidateDeleteKubernetesNodeGroup", func(t *testing.T) {
224+
err := v1.ValidateDeleteKubernetesNodeGroup(ctx, client, v1.DeleteNodeGroupArgs{
225+
ID: v1.CloudProviderResourceID("test-node-group"),
226+
})
227+
require.NoError(t, err, "ValidateDeleteKubernetesNodeGroup should pass")
228+
})
229+
230+
t.Run("ValidateDeleteKubernetesCluster", func(t *testing.T) {
231+
err := v1.ValidateDeleteKubernetesCluster(ctx, client, v1.DeleteClusterArgs{
232+
ID: v1.CloudProviderResourceID("test-cluster"),
233+
})
234+
require.NoError(t, err, "ValidateDeleteKubernetesCluster should pass")
235+
})
236+
}

v1/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ type CloudClient interface {
4343
CloudInstanceTags
4444
UpdateHandler
4545
CloudMaintainVPC
46+
CloudMaintainKubernetes
4647
}

v1/kubernetes.go

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package v1
33
import "context"
44

55
type Cluster struct {
6+
// The ID assigned by the cloud provider to the cluster.
7+
ID CloudProviderResourceID
8+
69
// The name of the cluster, displayed on clients.
710
Name string
811

912
// The unique ID used to associate with this cluster.
1013
RefID string
1114

12-
// The ID assigned by the cloud provider to the cluster.
13-
CloudID string
14-
1515
// The cloud provider that manages the cluster.
1616
Provider string
1717

@@ -49,6 +49,10 @@ type NodeGroup struct {
4949

5050
// The unique ID used to associate with this node group.
5151
RefID string
52+
53+
// The ID assigned by the cloud provider to the node group.
54+
ID CloudProviderResourceID
55+
5256
// The minimum number of nodes in the node group.
5357
MinNodeCount int
5458

@@ -57,15 +61,21 @@ type NodeGroup struct {
5761

5862
// The instance type of the nodes in the node group.
5963
InstanceType string
64+
65+
// The disk size of the nodes in the node group.
66+
DiskSizeGiB int
6067
}
6168

6269
type ClusterStatus string
6370

6471
const (
72+
ClusterStatusUnknown ClusterStatus = "unknown"
6573
ClusterStatusPending ClusterStatus = "pending"
6674
ClusterStatusAvailable ClusterStatus = "available"
6775
)
6876

77+
type CloudProviderResourceID string
78+
6979
type CreateClusterArgs struct {
7080
Name string
7181
RefID string
@@ -76,7 +86,7 @@ type CreateClusterArgs struct {
7686
}
7787

7888
type PutUserArgs struct {
79-
ClusterRefID string
89+
ClusterID CloudProviderResourceID
8090
Username string
8191
RSAPEMBase64 string
8292
}
@@ -91,8 +101,12 @@ type PutUserResponse struct {
91101
KubeconfigBase64 string
92102
}
93103

104+
type GetClusterArgs struct {
105+
ID CloudProviderResourceID
106+
}
107+
94108
type CreateNodeGroupArgs struct {
95-
ClusterRefID string
109+
ClusterID CloudProviderResourceID
96110
Name string
97111
RefID string
98112
MinNodeCount int
@@ -101,26 +115,105 @@ type CreateNodeGroupArgs struct {
101115
DiskSizeGiB int
102116
}
103117

118+
type GetNodeGroupArgs struct {
119+
ID CloudProviderResourceID
120+
}
121+
122+
type ModifyNodeGroupArgs struct {
123+
ID CloudProviderResourceID
124+
MinNodeCount int
125+
MaxNodeCount int
126+
}
127+
128+
type DeleteNodeGroupArgs struct {
129+
ID CloudProviderResourceID
130+
}
131+
104132
type CreateNodeGroupResponse struct {
105-
ClusterRefID string
133+
ID CloudProviderResourceID
106134
Name string
107135
RefID string
108-
}
109-
110-
type GetClusterArgs struct {
111-
RefID string
112-
CloudID string
113-
Location string
136+
MinNodeCount int
137+
MaxNodeCount int
138+
InstanceType string
139+
DiskSizeGiB int
114140
}
115141

116142
type DeleteClusterArgs struct {
117-
ClusterRefID string
143+
ID CloudProviderResourceID
118144
}
119145

120146
type CloudMaintainKubernetes interface {
121147
CreateCluster(ctx context.Context, args CreateClusterArgs) (*Cluster, error)
122148
GetCluster(ctx context.Context, args GetClusterArgs) (*Cluster, error)
123149
PutUser(ctx context.Context, args PutUserArgs) (*PutUserResponse, error)
124150
CreateNodeGroup(ctx context.Context, args CreateNodeGroupArgs) (*CreateNodeGroupResponse, error)
151+
GetNodeGroup(ctx context.Context, args GetNodeGroupArgs) (*NodeGroup, error)
152+
ModifyNodeGroup(ctx context.Context, args ModifyNodeGroupArgs) error
153+
DeleteNodeGroup(ctx context.Context, args DeleteNodeGroupArgs) error
125154
DeleteCluster(ctx context.Context, args DeleteClusterArgs) error
126155
}
156+
157+
func ValidateCreateKubernetesCluster(ctx context.Context, client CloudMaintainKubernetes, attrs CreateClusterArgs) error {
158+
_, err := client.CreateCluster(ctx, attrs)
159+
if err != nil {
160+
return err
161+
}
162+
return nil
163+
}
164+
165+
func ValidateGetKubernetesCluster(ctx context.Context, client CloudMaintainKubernetes, attrs GetClusterArgs) error {
166+
_, err := client.GetCluster(ctx, attrs)
167+
if err != nil {
168+
return err
169+
}
170+
return nil
171+
}
172+
173+
func ValidateGetKubernetesClusterCredentials(ctx context.Context, client CloudMaintainKubernetes, attrs GetClusterArgs) error {
174+
_, err := client.GetCluster(ctx, attrs)
175+
if err != nil {
176+
return err
177+
}
178+
return nil
179+
}
180+
181+
func ValidateCreateKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs CreateNodeGroupArgs) error {
182+
_, err := client.CreateNodeGroup(ctx, attrs)
183+
if err != nil {
184+
return err
185+
}
186+
return nil
187+
}
188+
189+
func ValidateGetKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs GetNodeGroupArgs) error {
190+
_, err := client.GetNodeGroup(ctx, attrs)
191+
if err != nil {
192+
return err
193+
}
194+
return nil
195+
}
196+
197+
func ValidateModifyKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs ModifyNodeGroupArgs) error {
198+
err := client.ModifyNodeGroup(ctx, attrs)
199+
if err != nil {
200+
return err
201+
}
202+
return nil
203+
}
204+
205+
func ValidateDeleteKubernetesNodeGroup(ctx context.Context, client CloudMaintainKubernetes, attrs DeleteNodeGroupArgs) error {
206+
err := client.DeleteNodeGroup(ctx, attrs)
207+
if err != nil {
208+
return err
209+
}
210+
return nil
211+
}
212+
213+
func ValidateDeleteKubernetesCluster(ctx context.Context, client CloudMaintainKubernetes, attrs DeleteClusterArgs) error {
214+
err := client.DeleteCluster(ctx, attrs)
215+
if err != nil {
216+
return err
217+
}
218+
return nil
219+
}

v1/networking.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ type PortMapping struct {
3333
FromPort int
3434
ToPort int
3535
}
36+
37+
func ValidateCreateVPC(ctx context.Context, client CloudMaintainVPC, attrs CreateVPCArgs) error {
38+
_, err := client.CreateVPC(ctx, attrs)
39+
if err != nil {
40+
return err
41+
}
42+
return nil
43+
}
44+
45+
func ValidateGetVPC(ctx context.Context, client CloudMaintainVPC, attrs GetVPCArgs) error {
46+
_, err := client.GetVPC(ctx, attrs)
47+
if err != nil {
48+
return err
49+
}
50+
return nil
51+
}
52+
53+
func ValidateDeleteVPC(ctx context.Context, client CloudMaintainVPC, attrs DeleteVPCArgs) error {
54+
err := client.DeleteVPC(ctx, attrs)
55+
if err != nil {
56+
return err
57+
}
58+
return nil
59+
}

v1/notimplemented.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,35 @@ func (c notImplCloudClient) GetVPC(_ context.Context, _ GetVPCArgs) (*VPC, error
138138
func (c notImplCloudClient) DeleteVPC(_ context.Context, _ DeleteVPCArgs) error {
139139
return ErrNotImplemented
140140
}
141+
142+
func (c notImplCloudClient) CreateCluster(_ context.Context, _ CreateClusterArgs) (*Cluster, error) {
143+
return nil, ErrNotImplemented
144+
}
145+
146+
func (c notImplCloudClient) GetCluster(_ context.Context, _ GetClusterArgs) (*Cluster, error) {
147+
return nil, ErrNotImplemented
148+
}
149+
150+
func (c notImplCloudClient) PutUser(_ context.Context, _ PutUserArgs) (*PutUserResponse, error) {
151+
return nil, ErrNotImplemented
152+
}
153+
154+
func (c notImplCloudClient) CreateNodeGroup(_ context.Context, _ CreateNodeGroupArgs) (*CreateNodeGroupResponse, error) {
155+
return nil, ErrNotImplemented
156+
}
157+
158+
func (c notImplCloudClient) GetNodeGroup(_ context.Context, _ GetNodeGroupArgs) (*NodeGroup, error) {
159+
return nil, ErrNotImplemented
160+
}
161+
162+
func (c notImplCloudClient) ModifyNodeGroup(_ context.Context, _ ModifyNodeGroupArgs) error {
163+
return ErrNotImplemented
164+
}
165+
166+
func (c notImplCloudClient) DeleteNodeGroup(_ context.Context, _ DeleteNodeGroupArgs) error {
167+
return ErrNotImplemented
168+
}
169+
170+
func (c notImplCloudClient) DeleteCluster(_ context.Context, _ DeleteClusterArgs) error {
171+
return ErrNotImplemented
172+
}

0 commit comments

Comments
 (0)