Skip to content

Commit b538fe2

Browse files
[CCE] add ENI network (#341)
[CCE] add ENI network Added ENI support for Turbo cluster === RUN TestCluster --- PASS: TestCluster (409.51s) PASS Debugger finished with the exit code 0 Reviewed-by: Anton Kachurin <[email protected]> Reviewed-by: Rodion Gyrbu <[email protected]>
1 parent 1f02786 commit b538fe2

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

acceptance/openstack/cce/helpers.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,44 @@ func CreateCluster(t *testing.T, vpcID, subnetID string) string {
4545
return cluster.Metadata.Id
4646
}
4747

48+
func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string, eniCidr string) string {
49+
client, err := clients.NewCceV3Client()
50+
th.AssertNoErr(t, err)
51+
52+
cluster, err := clusters.Create(client, clusters.CreateOpts{
53+
Kind: "Cluster",
54+
ApiVersion: "v3",
55+
Metadata: clusters.CreateMetaData{
56+
Name: strings.ToLower(tools.RandomString("cce-gopher-turbo-", 4)),
57+
},
58+
Spec: clusters.Spec{
59+
Category: "Turbo",
60+
Type: "VirtualMachine",
61+
Flavor: "cce.s1.small",
62+
HostNetwork: clusters.HostNetworkSpec{
63+
VpcId: vpcID,
64+
SubnetId: subnetID,
65+
},
66+
ContainerNetwork: clusters.ContainerNetworkSpec{
67+
Mode: "eni",
68+
},
69+
EniNetwork: &clusters.EniNetworkSpec{
70+
SubnetId: eniSubnetID,
71+
Cidr: eniCidr,
72+
},
73+
Authentication: clusters.AuthenticationSpec{
74+
Mode: "rbac",
75+
AuthenticatingProxy: make(map[string]string),
76+
},
77+
KubernetesSvcIpRange: "10.247.0.0/16",
78+
},
79+
}).Extract()
80+
th.AssertNoErr(t, err)
81+
82+
th.AssertNoErr(t, waitForClusterToActivate(client, cluster.Metadata.Id, 30*60))
83+
return cluster.Metadata.Id
84+
}
85+
4886
func DeleteCluster(t *testing.T, clusterID string) {
4987
client, err := clients.NewCceV3Client()
5088
th.AssertNoErr(t, err)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package v3
2+
3+
import (
4+
"testing"
5+
6+
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
7+
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/cce"
8+
"github.com/stretchr/testify/suite"
9+
)
10+
11+
type testCluster struct {
12+
suite.Suite
13+
14+
vpcID string
15+
subnetID string
16+
clusterID string
17+
eniSubnetID string
18+
eniCidr string
19+
}
20+
21+
func TestCluster(t *testing.T) {
22+
suite.Run(t, new(testCluster))
23+
}
24+
25+
func (s *testCluster) SetupSuite() {
26+
t := s.T()
27+
s.vpcID = clients.EnvOS.GetEnv("VPC_ID")
28+
s.subnetID = clients.EnvOS.GetEnv("NETWORK_ID")
29+
s.eniSubnetID = clients.EnvOS.GetEnv("ENI_SUBNET_ID")
30+
s.eniCidr = "10.0.0.0/14"
31+
if s.vpcID == "" || s.subnetID == "" || s.eniSubnetID == "" {
32+
t.Skip("OS_VPC_ID, OS_NETWORK_ID and OS_ENI_SUBNET_ID are required for this test")
33+
}
34+
s.clusterID = cce.CreateTurboCluster(t, s.vpcID, s.subnetID, s.eniSubnetID, s.eniCidr)
35+
}
36+
37+
func (s *testCluster) TearDownSuite() {
38+
t := s.T()
39+
if s.clusterID != "" {
40+
cce.DeleteCluster(t, s.clusterID)
41+
s.clusterID = ""
42+
}
43+
}

openstack/cce/v3/clusters/results.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type MetaData struct {
4242

4343
// Specifications to create a cluster
4444
type Spec struct {
45+
// Cluster category: CCE, Turbo
46+
Category string `json:"category,omitempty"`
4547
// Cluster Type: VirtualMachine, BareMetal, or Windows
4648
Type string `json:"type" required:"true"`
4749
// Cluster specifications
@@ -56,6 +58,8 @@ type Spec struct {
5658
HostNetwork HostNetworkSpec `json:"hostNetwork" required:"true"`
5759
// Container network parameters
5860
ContainerNetwork ContainerNetworkSpec `json:"containerNetwork" required:"true"`
61+
// ENI network parameters
62+
EniNetwork *EniNetworkSpec `json:"eniNetwork,omitempty"`
5963
// Authentication parameters
6064
Authentication AuthenticationSpec `json:"authentication,omitempty"`
6165
// Charging mode of the cluster, which is 0 (on demand)
@@ -90,6 +94,13 @@ type ContainerNetworkSpec struct {
9094
Cidr string `json:"cidr,omitempty"`
9195
}
9296

97+
type EniNetworkSpec struct {
98+
// Eni network subnet id
99+
SubnetId string `json:"eniSubnetId" required:"true"`
100+
// Eni network cidr
101+
Cidr string `json:"eniSubnetCIDR" required:"true"`
102+
}
103+
93104
// Authentication parameters
94105
type AuthenticationSpec struct {
95106
// Authentication mode: rbac , x509 or authenticating_proxy

openstack/cce/v3/clusters/testing/requests_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,79 @@ func TestCreateV3Cluster(t *testing.T) {
165165

166166
}
167167

168+
func TestCreateV3TurboCluster(t *testing.T) {
169+
th.SetupHTTP()
170+
defer th.TeardownHTTP()
171+
172+
th.Mux.HandleFunc("/api/v3/projects/c59fd21fd2a94963b822d8985b884673/clusters", func(w http.ResponseWriter, r *http.Request) {
173+
th.TestMethod(t, r, "POST")
174+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
175+
th.TestHeader(t, r, "Content-Type", "application/json")
176+
th.TestHeader(t, r, "Accept", "application/json")
177+
178+
th.TestJSONRequest(t, r, `
179+
{
180+
"kind": "Cluster",
181+
"apiversion": "v3",
182+
"metadata": {
183+
"name": "test-turbo-cluster"
184+
},
185+
"spec": {
186+
"category": "Turbo",
187+
"type": "VirtualMachine",
188+
"flavor": "cce.s2.small",
189+
"version": "v1.19.10-r0",
190+
"hostNetwork": {
191+
"vpc": "3305eb40-2707-4940-921c-9f335f84a2ca",
192+
"subnet": "00e41db7-e56b-4946-bf91-27bb9effd664"
193+
},
194+
"containerNetwork": {
195+
"mode": "eni"
196+
},
197+
"eniNetwork": {
198+
"eniSubnetId": "417dcc1f-95d7-43e7-8533-ab078d266303",
199+
"eniSubnetCIDR": "192.168.0.0/24"
200+
},
201+
"authentication": {
202+
"mode": "rbac",
203+
"authenticatingProxy": {}
204+
}
205+
}
206+
207+
}
208+
`)
209+
210+
w.Header().Set("Content-Type", "application/json")
211+
w.WriteHeader(http.StatusCreated)
212+
_, _ = fmt.Fprint(w, Output)
213+
})
214+
options := clusters.CreateOpts{Kind: "Cluster",
215+
ApiVersion: "v3",
216+
Metadata: clusters.CreateMetaData{Name: "test-turbo-cluster"},
217+
Spec: clusters.Spec{Type: "VirtualMachine",
218+
Category: "Turbo",
219+
Flavor: "cce.s2.small",
220+
Version: "v1.19.10-r0",
221+
HostNetwork: clusters.HostNetworkSpec{
222+
VpcId: "3305eb40-2707-4940-921c-9f335f84a2ca",
223+
SubnetId: "00e41db7-e56b-4946-bf91-27bb9effd664"},
224+
ContainerNetwork: clusters.ContainerNetworkSpec{Mode: "eni"},
225+
EniNetwork: &clusters.EniNetworkSpec{
226+
SubnetId: "417dcc1f-95d7-43e7-8533-ab078d266303",
227+
Cidr: "192.168.0.0/24",
228+
},
229+
Authentication: clusters.AuthenticationSpec{
230+
Mode: "rbac",
231+
AuthenticatingProxy: make(map[string]string)},
232+
},
233+
}
234+
actual, err := clusters.Create(fake.ServiceClient(), options).Extract()
235+
th.AssertNoErr(t, err)
236+
expected := Expected
237+
th.AssertDeepEquals(t, expected, actual)
238+
239+
}
240+
168241
func TestUpdateV3Cluster(t *testing.T) {
169242
th.SetupHTTP()
170243
defer th.TeardownHTTP()
@@ -208,3 +281,18 @@ func TestDeleteV3Cluster(t *testing.T) {
208281
th.AssertNoErr(t, err)
209282

210283
}
284+
285+
func TestDeleteV3TurboCluster(t *testing.T) {
286+
th.SetupHTTP()
287+
defer th.TeardownHTTP()
288+
289+
th.Mux.HandleFunc("/api/v3/projects/c59fd21fd2a94963b822d8985b884673/clusters/daa97872-59d7-11e8-a787-0255ac101f54", func(w http.ResponseWriter, r *http.Request) {
290+
th.TestMethod(t, r, "DELETE")
291+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
292+
w.WriteHeader(http.StatusOK)
293+
})
294+
295+
err := clusters.Delete(fake.ServiceClient(), "daa97872-59d7-11e8-a787-0255ac101f54").ExtractErr()
296+
th.AssertNoErr(t, err)
297+
298+
}

params.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func BuildRequestBody(opts interface{}, parent string) (map[string]interface{},
5050
v := optsValue.Field(i)
5151
f := optsType.Field(i)
5252

53+
// nolint
5354
if f.Name != strings.Title(f.Name) {
5455
// fmt.Printf("Skipping field: %s...\n", f.Name)
5556
continue

0 commit comments

Comments
 (0)