Skip to content

Commit 282edd1

Browse files
support eni network for cce turbo cluster (#287)
[CCE] support ENI network for CCE turbo cluster Resolves #284 Release notes added Tests added/passed Docs updated Examples added Reviewed-by: Anton Sidelnikov <None> Reviewed-by: Irina Pereiaslavskaia <irina.pereyaslavskaya@gmail.com>
1 parent cb90be5 commit 282edd1

5 files changed

Lines changed: 220 additions & 0 deletions

File tree

doc/source/sdk/resources/cce/v3/cluster.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ The ``Cluster`` class inherits from
1818
.. autoclass:: otcextensions.sdk.cce.v3.cluster.HostNetworkSpec
1919
:members:
2020

21+
.. autoclass:: otcextensions.sdk.cce.v3.cluster.EniNetworkSpec
22+
:members:
23+
2124
.. autoclass:: otcextensions.sdk.cce.v3.cluster.StatusSpec
2225
:members:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
Create CCE Cluster
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
22+
attrs = {
23+
"kind": "Cluster",
24+
"apiVersion": "v3",
25+
"metadata": {
26+
"name": "turbo-cluster",
27+
},
28+
"spec": {
29+
"type": "VirtualMachine",
30+
"flavor": "cce.s1.small",
31+
"version": "v1.19.10-r0",
32+
"az": "eu-de-01",
33+
"hostNetwork": {
34+
"vpc": "05c33818-78df-4329-b546-5df2f1aa823e",
35+
"subnet": "9f0c8ef2-c608-4238-88be-87bce5fe90da",
36+
},
37+
"containerNetwork": {
38+
"mode": "eni",
39+
},
40+
"eniNetwork": {
41+
"eniSubnetId": "417dcc1f-95d7-43e7-8533-ab078d266303",
42+
"eniSubnetCIDR": "10.0.0.0/14",
43+
},
44+
"authentication": {
45+
"mode": "rbac",
46+
"authenticatingProxy": {}
47+
},
48+
"billingMode": 0,
49+
"kubernetesSvcIpRange": "10.247.0.0/16",
50+
"kubeProxyMode": "iptables"
51+
}
52+
}
53+
54+
conn.cce.create_cluster(**attrs)

otcextensions/sdk/cce/v3/cluster.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class HostNetworkSpec(resource.Resource):
2727
router_id = resource.Body('vpc')
2828

2929

30+
class EniNetworkSpec(resource.Resource):
31+
32+
# Properties
33+
#: IPv4 Subnet ID of the ENI container subnet.
34+
eni_subnet_id = resource.Body('eniSubnetId')
35+
#: ENI subnet CIDR block.
36+
eni_subnet_cidr = resource.Body('eniSubnetCIDR')
37+
38+
3039
class ClusterSpec(resource.Resource):
3140

3241
#: Authentication
@@ -52,6 +61,8 @@ class ClusterSpec(resource.Resource):
5261
type = resource.Body('type')
5362
#: Cluster version ['v1.11.7-r2', 'v1.13.10-r0'].
5463
version = resource.Body('version')
64+
#: Eni network parameters.
65+
eni_network = resource.Body('eniNetwork', type=EniNetworkSpec)
5566

5667

5768
class StatusSpec(_base.StatusSpec):
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
import copy
13+
14+
from keystoneauth1 import adapter
15+
16+
import mock
17+
18+
from openstack.tests.unit import base
19+
20+
from otcextensions.sdk.cce.v3 import cluster as _cluster
21+
22+
OS_HEADERS = {
23+
'Content-Type': 'application/json',
24+
}
25+
26+
EXAMPLE_LIST = {
27+
'kind': 'Cluster',
28+
'apiVersion': 'v3',
29+
'items': [
30+
{
31+
'kind': 'Cluster',
32+
'apiVersion': 'v3',
33+
'metadata': {
34+
'name': 'mycluster-turbo-demo',
35+
'uid': '40c54866-38c5-11e9-b246-0255ac101413',
36+
'creationTimestamp': '2019-02-25 06:19:05.789462 +0000 UTC',
37+
'updateTimestamp': '2019-02-25 06:26:14.457426 +0000 UTC'
38+
},
39+
'spec': {
40+
'type': 'VirtualMachine',
41+
'flavor': 'cce.s1.small',
42+
'version': 'v1.13.10-r0',
43+
'az': 'eu-de-01',
44+
'supportIstio': True,
45+
'description': 'thisisademocluster',
46+
'hostNetwork': {
47+
'vpc': 'a8cc62dc-acc2-47d0-9bfb-3b1d776c520b',
48+
'subnet': '6d9e5355-85af-4a89-af28-243edb700db6'
49+
},
50+
'containerNetwork': {
51+
'mode': 'eni',
52+
'cidr': '172.16.0.0/16'
53+
},
54+
'eniNetwork': {
55+
'eniSubnetId': 'eni-0e5f8f8c',
56+
'eniSubnetCIDR': '172.16.0.0/16',
57+
},
58+
'authentication': {
59+
'mode': 'rbac',
60+
'authenticatingProxy': {}
61+
},
62+
'billingMode': 0,
63+
"kubeProxyMode": "ipvs",
64+
},
65+
'status': {
66+
'phase': 'Available',
67+
'endpoints': {
68+
'internal': 'https://192.168.0.129:5443',
69+
'external_otc': 'https://40c54866-38c5-'
70+
}
71+
}
72+
}
73+
]
74+
}
75+
76+
77+
class TestCluster(base.TestCase):
78+
79+
def setUp(self):
80+
super(TestCluster, self).setUp()
81+
self.sess = mock.Mock(spec=adapter.Adapter)
82+
self.sess.get = mock.Mock()
83+
self.sess.delete = mock.Mock()
84+
self.sess.post = mock.Mock()
85+
self.sess.put = mock.Mock()
86+
self.sess.default_microversion = '1'
87+
self.sess._get_connection = mock.Mock(return_value=self.cloud)
88+
89+
self.sot = _cluster.Cluster()
90+
91+
self.sot_expected = _cluster.Cluster(**EXAMPLE_LIST['items'][0])
92+
93+
def test_basic(self):
94+
sot = _cluster.Cluster()
95+
self.assertEqual('', sot.resource_key)
96+
self.assertEqual('', sot.resources_key)
97+
self.assertEqual('/clusters',
98+
sot.base_path)
99+
self.assertTrue(sot.allow_list)
100+
self.assertTrue(sot.allow_create)
101+
self.assertTrue(sot.allow_fetch)
102+
self.assertTrue(sot.allow_commit)
103+
self.assertTrue(sot.allow_delete)
104+
105+
def test_make_it(self):
106+
obj = EXAMPLE_LIST['items'][0]
107+
sot = _cluster.Cluster.existing(**obj)
108+
self.assertEqual(obj['metadata']['uid'], sot.id)
109+
self.assertEqual(obj['kind'], sot.kind)
110+
# self.assertEqual(obj['spec'], sot.spec)
111+
# self.assertEqual(obj['status'], sot.status)
112+
113+
def test_list(self):
114+
mock_response = mock.Mock()
115+
mock_response.status_code = 200
116+
mock_response.json.return_value = copy.deepcopy(EXAMPLE_LIST)
117+
118+
self.sess.get.return_value = mock_response
119+
120+
result = list(
121+
self.sot.list(
122+
self.sess,
123+
)
124+
)
125+
126+
self.sess.get.assert_called_once_with(
127+
'/clusters',
128+
params={},
129+
headers={
130+
'Accept': 'application/json',
131+
'Content-Type': 'application/json'
132+
}
133+
)
134+
135+
expected_list = [
136+
self.sot_expected,
137+
]
138+
139+
self.assertEqual(
140+
set(i.id for i in expected_list),
141+
set(i.id for i in result))
142+
143+
def test_get_status(self):
144+
data = EXAMPLE_LIST['items'][0]
145+
cluster = _cluster.Cluster(**data)
146+
147+
self.assertEqual(data['status']['phase'], getattr(cluster,
148+
'status.status'))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
**[CCE]** Support ENI network for turbo clusters.

0 commit comments

Comments
 (0)