Browse Source

Allow setting network, subnet and FIP when creating cluster

When using a public cluster template, user still need the capability
to reuse their existing network/subnet, and they also need to be
able to turn of/off the floatingip to overwrite the setting in the
public template. This patch supports that by adding those three
items as parameters when creating cluster.

Story: 2006208
Task: 35797

Change-Id: I11579ff6b83d133c71c2cbf49ee4b20996dfb918
changes/82/671182/6
Feilong Wang 3 years ago
parent
commit
32989b4f7b
  1. 2
      contrib/drivers/heat/dcos_centos_template_def.py
  2. 9
      magnum/api/controllers/v1/bay.py
  3. 35
      magnum/api/controllers/v1/cluster.py
  4. 40
      magnum/db/sqlalchemy/alembic/versions/47380964133d_add_network_subnet_fip_to_cluster.py
  5. 3
      magnum/db/sqlalchemy/models.py
  6. 3
      magnum/drivers/heat/k8s_coreos_template_def.py
  7. 3
      magnum/drivers/heat/k8s_fedora_template_def.py
  8. 4
      magnum/drivers/heat/k8s_template_def.py
  9. 3
      magnum/drivers/heat/swarm_fedora_template_def.py
  10. 3
      magnum/drivers/heat/swarm_mode_template_def.py
  11. 6
      magnum/drivers/heat/template_def.py
  12. 3
      magnum/drivers/mesos_ubuntu_v1/template_def.py
  13. 8
      magnum/objects/cluster.py
  14. 9
      magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py
  15. 3
      magnum/tests/unit/conductor/handlers/test_mesos_cluster_conductor.py
  16. 5
      magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py
  17. 3
      magnum/tests/unit/db/utils.py
  18. 10
      magnum/tests/unit/drivers/test_template_definition.py
  19. 2
      magnum/tests/unit/objects/test_objects.py
  20. 8
      releasenotes/notes/allow-setting-network-subnet-FIP-when-creating-cluster-ae0cda35ade28a9f.yaml

2
contrib/drivers/heat/dcos_centos_template_def.py

@ -156,7 +156,7 @@ class DcosCentosTemplateDefinition(template_def.BaseTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster)
template_def.add_lb_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)

9
magnum/api/controllers/v1/bay.py

@ -142,6 +142,15 @@ class Bay(base.APIBase):
bay_faults = wsme.wsattr(wtypes.DictType(wtypes.text, wtypes.text))
"""Fault info collected from the heat resources of this bay"""
fixed_network = wtypes.StringType(min_length=1, max_length=255)
"""The fixed network name to attach to the Cluster"""
fixed_subnet = wtypes.StringType(min_length=1, max_length=255)
"""The fixed subnet name to attach to the Cluster"""
floating_ip_enabled = wsme.wsattr(types.boolean, default=True)
"""Indicates whether created clusters should have a floating ip or not."""
def __init__(self, **kwargs):
super(Bay, self).__init__()

35
magnum/api/controllers/v1/cluster.py

@ -174,6 +174,15 @@ class Cluster(base.APIBase):
faults = wsme.wsattr(wtypes.DictType(wtypes.text, wtypes.text))
"""Fault info collected from the heat resources of this cluster"""
fixed_network = wtypes.StringType(min_length=1, max_length=255)
"""The fixed network name to attach to the Cluster"""
fixed_subnet = wtypes.StringType(min_length=1, max_length=255)
"""The fixed subnet name to attach to the Cluster"""
floating_ip_enabled = wsme.wsattr(types.boolean, default=True)
"""Indicates whether created clusters should have a floating ip or not."""
def __init__(self, **kwargs):
super(Cluster, self).__init__()
self.fields = []
@ -236,7 +245,10 @@ class Cluster(base.APIBase):
created_at=timeutils.utcnow(),
updated_at=timeutils.utcnow(),
coe_version=None,
container_version=None)
container_version=None,
fixed_network=None,
fixed_subnet=None,
floating_ip_enabled=True)
return cls._convert_with_links(sample, 'http://localhost:9511', expand)
@ -471,23 +483,20 @@ class ClustersController(base.Controller):
if cluster.keypair is None:
cluster.keypair = cluster_template.keypair_id
# If docker_volume_size is not present, use cluster_template value
if (cluster.docker_volume_size == wtypes.Unset or
not cluster.docker_volume_size):
cluster.docker_volume_size = cluster_template.docker_volume_size
# If labels is not present, use cluster_template value
if cluster.labels == wtypes.Unset:
cluster.labels = cluster_template.labels
# If master_flavor_id is not present, use cluster_template value
if (cluster.master_flavor_id == wtypes.Unset or
not cluster.master_flavor_id):
cluster.master_flavor_id = cluster_template.master_flavor_id
# If floating_ip_enabled is not present, use cluster_template value
if cluster.floating_ip_enabled == wtypes.Unset:
cluster.floating_ip_enabled = cluster_template.floating_ip_enabled
# If flavor_id is not present, use cluster_template value
if cluster.flavor_id == wtypes.Unset or not cluster.flavor_id:
cluster.flavor_id = cluster_template.flavor_id
attributes = ["docker_volume_size", "master_flavor_id", "flavor_id",
"fixed_network", "fixed_subnet"]
for attr in attributes:
if (getattr(cluster, attr) == wtypes.Unset or
not getattr(cluster, attr)):
setattr(cluster, attr, getattr(cluster_template, attr))
cluster_dict = cluster.as_dict()

40
magnum/db/sqlalchemy/alembic/versions/47380964133d_add_network_subnet_fip_to_cluster.py

@ -0,0 +1,40 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""add-network-subnet-fip-to-cluster
Revision ID: 47380964133d
Revises: 461d798132c7
Create Date: 2019-07-17 13:17:58.760452
"""
# revision identifiers, used by Alembic.
revision = '47380964133d'
down_revision = '461d798132c7'
from alembic import op
from oslo_db.sqlalchemy.types import String
import sqlalchemy as sa
from sqlalchemy.dialects.mysql import TINYTEXT
def upgrade():
op.add_column('cluster', sa.Column('fixed_network',
String(255, mysql_ndb_type=TINYTEXT),
nullable=True))
op.add_column('cluster', sa.Column('fixed_subnet',
String(255, mysql_ndb_type=TINYTEXT),
nullable=True))
op.add_column('cluster', sa.Column('floating_ip_enabled',
sa.Boolean(),
default=False))

3
magnum/db/sqlalchemy/models.py

@ -144,6 +144,9 @@ class Cluster(Base):
# so, we use 512 chars to get some buffer.
ca_cert_ref = Column(String(512, mysql_ndb_type=mysql_TEXT))
magnum_cert_ref = Column(String(512, mysql_ndb_type=mysql_TEXT))
fixed_network = Column(String(255, mysql_ndb_type=TINYTEXT))
fixed_subnet = Column(String(255, mysql_ndb_type=TINYTEXT))
floating_ip_enabled = Column(Boolean, default=True)
class ClusterTemplate(Base):

3
magnum/drivers/heat/k8s_coreos_template_def.py

@ -157,7 +157,8 @@ class CoreOSK8sTemplateDefinition(k8s_template_def.K8sTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster_template,
cluster)
template_def.add_etcd_volume_env_file(env_files, cluster_template)
template_def.add_volume_env_file(env_files, cluster)
template_def.add_lb_env_file(env_files, cluster_template)

3
magnum/drivers/heat/k8s_fedora_template_def.py

@ -216,7 +216,8 @@ class K8sFedoraTemplateDefinition(k8s_template_def.K8sTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster_template,
cluster)
template_def.add_etcd_volume_env_file(env_files, cluster_template)
template_def.add_volume_env_file(env_files, cluster)
template_def.add_lb_env_file(env_files, cluster_template)

4
magnum/drivers/heat/k8s_template_def.py

@ -59,9 +59,9 @@ class K8sTemplateDefinition(template_def.BaseTemplateDefinition):
cluster_template_attr='external_network_id',
required=True)
self.add_parameter('fixed_network',
cluster_template_attr='fixed_network')
cluster_attr='fixed_network')
self.add_parameter('fixed_subnet',
cluster_template_attr='fixed_subnet')
cluster_attr='fixed_subnet')
self.add_parameter('network_driver',
cluster_template_attr='network_driver')
self.add_parameter('volume_driver',

3
magnum/drivers/heat/swarm_fedora_template_def.py

@ -155,7 +155,8 @@ class SwarmFedoraTemplateDefinition(template_def.BaseTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster_template,
cluster)
template_def.add_volume_env_file(env_files, cluster)
template_def.add_lb_env_file(env_files, cluster_template)

3
magnum/drivers/heat/swarm_mode_template_def.py

@ -182,7 +182,8 @@ class SwarmModeTemplateDefinition(template_def.BaseTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster_template,
cluster)
template_def.add_volume_env_file(env_files, cluster)
template_def.add_lb_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)

6
magnum/drivers/heat/template_def.py

@ -514,7 +514,7 @@ def add_fip_env_file(env_files, cluster_template, cluster):
)
master_lb_fip_enabled = strutils.bool_from_string(lb_fip_enabled)
if cluster_template.floating_ip_enabled:
if cluster.floating_ip_enabled:
env_files.append(COMMON_ENV_PATH + 'enable_floating_ip.yaml')
else:
env_files.append(COMMON_ENV_PATH + 'disable_floating_ip.yaml')
@ -525,8 +525,8 @@ def add_fip_env_file(env_files, cluster_template, cluster):
env_files.append(COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml')
def add_priv_net_env_file(env_files, cluster_template):
if cluster_template.fixed_network:
def add_priv_net_env_file(env_files, cluster_template, cluster):
if (cluster.fixed_network or cluster_template.fixed_network):
env_files.append(COMMON_ENV_PATH + 'no_private_network.yaml')
else:
env_files.append(COMMON_ENV_PATH + 'with_private_network.yaml')

3
magnum/drivers/mesos_ubuntu_v1/template_def.py

@ -121,7 +121,8 @@ class UbuntuMesosTemplateDefinition(template_def.BaseTemplateDefinition):
def get_env_files(self, cluster_template, cluster):
env_files = []
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_priv_net_env_file(env_files, cluster_template,
cluster)
template_def.add_lb_env_file(env_files, cluster_template)
return env_files

8
magnum/objects/cluster.py

@ -51,8 +51,9 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
# Version 1.19: Added nodegroups, default_ng_worker, default_ng_master
# Version 1.20: Fields node_count, master_count, node_addresses,
# master_addresses are now properties.
# Version 1.21 Added fixed_network, fixed_subnet, floating_ip_enabled
VERSION = '1.20'
VERSION = '1.21'
dbapi = dbapi.get_instance()
@ -84,7 +85,10 @@ class Cluster(base.MagnumPersistentObject, base.MagnumObject,
'trustee_password': fields.StringField(nullable=True),
'trustee_user_id': fields.StringField(nullable=True),
'coe_version': fields.StringField(nullable=True),
'container_version': fields.StringField(nullable=True)
'container_version': fields.StringField(nullable=True),
'fixed_network': fields.StringField(nullable=True),
'fixed_subnet': fields.StringField(nullable=True),
'floating_ip_enabled': fields.BooleanField(default=True),
}
@staticmethod

9
magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py

@ -118,7 +118,10 @@ class TestClusterConductorWithK8s(base.TestCase):
'master_flavor_id': 'master_flavor_id',
'flavor_id': 'flavor_id',
'project_id': 'project_id',
'keystone_auth_default_policy': self.keystone_auth_default_policy
'keystone_auth_default_policy': self.keystone_auth_default_policy,
'fixed_network': 'fixed_network',
'fixed_subnet': 'fixed_subnet',
'floating_ip_enabled': False,
}
self.worker_ng_dict = {
'uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a53',
@ -554,6 +557,8 @@ class TestClusterConductorWithK8s(base.TestCase):
'docker_volume_size': 20,
'master_flavor': 'master_flavor_id',
'minion_flavor': 'flavor_id',
'fixed_network': 'fixed_network',
'fixed_subnet': 'fixed_subnet',
'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
'flannel_backend': 'vxlan',
'flannel_network_cidr': '10.101.0.0/16',
@ -607,7 +612,7 @@ class TestClusterConductorWithK8s(base.TestCase):
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/with_private_network.yaml',
['../../common/templates/environments/no_private_network.yaml',
'../../common/templates/environments/no_etcd_volume.yaml',
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',

3
magnum/tests/unit/conductor/handlers/test_mesos_cluster_conductor.py

@ -72,6 +72,9 @@ class TestClusterConductorWithMesos(base.TestCase):
'mesos_slave_executor_env_variables': '{}',
'mesos_slave_work_dir': '/tmp/mesos/slave'
},
'fixed_network': '',
'fixed_subnet': '',
'floating_ip_enabled': False,
}
self.worker_ng_dict = {
'uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a53',

5
magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py

@ -81,7 +81,10 @@ class TestClusterConductorWithSwarm(base.TestCase):
'rexray_preempt': 'False',
'swarm_strategy': 'spread',
'availability_zone': 'az_1'},
'coe_version': 'fake-version'
'coe_version': 'fake-version',
'fixed_network': '',
'fixed_subnet': '',
'floating_ip_enabled': False,
}
self.worker_ng_dict = {
'uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a53',

3
magnum/tests/unit/db/utils.py

@ -98,6 +98,9 @@ def get_test_cluster(**kw):
'labels': kw.get('labels'),
'master_flavor_id': kw.get('master_flavor_id', None),
'flavor_id': kw.get('flavor_id', None),
'fixed_network': kw.get('fixed_network', None),
'fixed_subnet': kw.get('fixed_subnet', None),
'floating_ip_enabled': kw.get('floating_ip_enabled', True),
}
if kw.pop('for_api_use', False):

10
magnum/tests/unit/drivers/test_template_definition.py

@ -219,7 +219,7 @@ class TemplateDefinitionTestCase(base.TestCase):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=False,
master_lb_enabled=False,
labels={})
mock_cluster = mock.MagicMock(labels={})
mock_cluster = mock.MagicMock(labels={}, floating_ip_enabled=False)
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
@ -235,7 +235,7 @@ class TemplateDefinitionTestCase(base.TestCase):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=False,
master_lb_enabled=True,
labels={})
mock_cluster = mock.MagicMock(labels={})
mock_cluster = mock.MagicMock(labels={}, floating_ip_enabled=False,)
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
@ -254,7 +254,8 @@ class TemplateDefinitionTestCase(base.TestCase):
labels={"master_lb_floating_ip_enabled": "true"}
)
mock_cluster = mock.MagicMock(
labels={"master_lb_floating_ip_enabled": "true"})
labels={"master_lb_floating_ip_enabled": "true"},
floating_ip_enabled=False,)
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
@ -273,7 +274,8 @@ class TemplateDefinitionTestCase(base.TestCase):
labels={"master_lb_floating_ip_enabled": "false"}
)
mock_cluster = mock.MagicMock(
labels={"master_lb_floating_ip_enabled": "false"})
labels={"master_lb_floating_ip_enabled": "false"},
floating_ip_enabled=False,)
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,

2
magnum/tests/unit/objects/test_objects.py

@ -355,7 +355,7 @@ class TestObject(test_base.TestCase, _TestObject):
# For more information on object version testing, read
# https://docs.openstack.org/magnum/latest/contributor/objects.html
object_data = {
'Cluster': '1.20-fcdb29a886bf9552cdac03470570024c',
'Cluster': '1.21-11ab13dfd5cb53578d398008d758dab8',
'ClusterTemplate': '1.19-3b0b2b3933d0955abf3ab40111744960',
'Certificate': '1.1-1924dc077daa844f0f9076332ef96815',
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',

8
releasenotes/notes/allow-setting-network-subnet-FIP-when-creating-cluster-ae0cda35ade28a9f.yaml

@ -0,0 +1,8 @@
---
features:
- |
When using a public cluster template, user still need the capability
to reuse their existing network/subnet, and they also need to be
able to turn of/off the floating IP to overwrite the setting in the
public template. Now this is supported by adding those three
items as parameters when creating cluster.
Loading…
Cancel
Save