Browse Source

Merge "Improve floating IP allocation"

changes/78/631378/17
Zuul 2 years ago
committed by Gerrit Code Review
parent
commit
d1957c71dc
  1. 2
      contrib/drivers/heat/dcos_centos_template_def.py
  2. 9
      doc/source/user/index.rst
  3. 2
      magnum/drivers/common/templates/environments/enable_floating_ip.yaml
  4. 2
      magnum/drivers/common/templates/environments/enable_lb_floating_ip.yaml
  5. 0
      magnum/drivers/common/templates/lb_api.yaml
  6. 52
      magnum/drivers/common/templates/lb_etcd.yaml
  7. 2
      magnum/drivers/heat/k8s_coreos_template_def.py
  8. 2
      magnum/drivers/heat/k8s_fedora_template_def.py
  9. 2
      magnum/drivers/heat/swarm_mode_template_def.py
  10. 18
      magnum/drivers/heat/template_def.py
  11. 5
      magnum/drivers/k8s_coreos_v1/templates/kubecluster.yaml
  12. 5
      magnum/drivers/k8s_fedora_atomic_v1/templates/kubecluster.yaml
  13. 7
      magnum/drivers/k8s_fedora_ironic_v1/templates/kubecluster.yaml
  14. 4
      magnum/drivers/mesos_ubuntu_v1/templates/mesoscluster.yaml
  15. 7
      magnum/drivers/swarm_fedora_atomic_v1/templates/cluster.yaml
  16. 2
      magnum/drivers/swarm_fedora_atomic_v2/templates/swarmcluster.yaml
  17. 12
      magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py
  18. 109
      magnum/tests/unit/drivers/test_template_definition.py
  19. 10
      releasenotes/notes/k8s-improve-floating-ip-enabled-84cd00224d6b7bc1.yaml

2
contrib/drivers/heat/dcos_centos_template_def.py

@ -158,6 +158,6 @@ class DcosCentosTemplateDefinition(template_def.BaseTemplateDefinition):
template_def.add_priv_net_env_file(env_files, cluster_template)
template_def.add_lb_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)
return env_files

9
doc/source/user/index.rst

@ -384,6 +384,9 @@ the table are linked to more details elsewhere in the user guide.
+---------------------------------------+--------------------+---------------+
| `tiller_namespace`_ | see below | see below |
+---------------------------------------+--------------------+---------------+
| `master_lb_floating_ip_enabled`_ | - true | see below |
| | - false | |
+---------------------------------------+--------------------+---------------+
Cluster
-------
@ -1232,6 +1235,12 @@ _`tiller_namespace`
Configure in which namespace tiller is going to be installed.
Default: magnum-tiller
_`master_lb_floating_ip_enabled`
Controls if Magnum allocates floating IP for the load balancer of master
nodes. This label only takes effect when the template property
``master_lb_enabled`` is set. If not specified, the default value is the same
as template property ``floating_ip_enabled``.
External load balancer for services
-----------------------------------

2
magnum/drivers/common/templates/environments/enable_floating_ip.yaml

@ -1,5 +1,3 @@
# Environment file to disable FloatingIP in a Kubernetes cluster by mapping
# FloatingIP-related resource types to OS::Neutron::FloatingIP
resource_registry:
"Magnum::FloatingIPAddressSwitcher": "../fragments/floating_ip_address_switcher_public.yaml"

2
magnum/drivers/common/templates/environments/enable_lb_floating_ip.yaml

@ -2,3 +2,5 @@
resource_registry:
"Magnum::Optional::Neutron::LBaaS::FloatingIP": "OS::Neutron::FloatingIP"
"Magnum::FloatingIPAddressSwitcher": "../fragments/floating_ip_address_switcher_public.yaml"

0
magnum/drivers/common/templates/lb.yaml → magnum/drivers/common/templates/lb_api.yaml

52
magnum/drivers/common/templates/lb_etcd.yaml

@ -0,0 +1,52 @@
# etcd service load balancer doesn't have floating IP associated.
heat_template_version: 2014-10-16
parameters:
fixed_subnet:
type: string
protocol:
type: string
default: TCP
constraints:
- allowed_values: ["TCP", "HTTP"]
port:
type: number
resources:
loadbalancer:
type: Magnum::Optional::Neutron::LBaaS::LoadBalancer
properties:
vip_subnet: {get_param: fixed_subnet}
listener:
type: Magnum::Optional::Neutron::LBaaS::Listener
properties:
loadbalancer: {get_resource: loadbalancer}
protocol: {get_param: protocol}
protocol_port: {get_param: port}
pool:
type: Magnum::Optional::Neutron::LBaaS::Pool
properties:
lb_algorithm: ROUND_ROBIN
listener: {get_resource: listener}
protocol: {get_param: protocol}
monitor:
type: Magnum::Optional::Neutron::LBaaS::HealthMonitor
properties:
type: TCP
delay: 5
max_retries: 5
timeout: 5
pool: { get_resource: pool }
outputs:
pool_id:
value: {get_resource: pool}
address:
value: {get_attr: [loadbalancer, vip_address]}

2
magnum/drivers/heat/k8s_coreos_template_def.py

@ -127,6 +127,6 @@ class CoreOSK8sTemplateDefinition(k8s_template_def.K8sTemplateDefinition):
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)
template_def.add_fip_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)
return env_files

2
magnum/drivers/heat/k8s_fedora_template_def.py

@ -162,6 +162,6 @@ class K8sFedoraTemplateDefinition(k8s_template_def.K8sTemplateDefinition):
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)
template_def.add_fip_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)
return env_files

2
magnum/drivers/heat/swarm_mode_template_def.py

@ -154,6 +154,6 @@ class SwarmModeTemplateDefinition(template_def.BaseTemplateDefinition):
template_def.add_priv_net_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)
template_def.add_fip_env_file(env_files, cluster_template)
template_def.add_fip_env_file(env_files, cluster_template, cluster)
return env_files

18
magnum/drivers/heat/template_def.py

@ -15,6 +15,7 @@ import abc
import ast
from oslo_log import log as logging
from oslo_utils import strutils
import re
import requests
import six
@ -385,15 +386,22 @@ def add_etcd_volume_env_file(env_files, cluster_template):
env_files.append(COMMON_ENV_PATH + 'with_etcd_volume.yaml')
def add_fip_env_file(env_files, cluster_template):
def add_fip_env_file(env_files, cluster_template, cluster):
lb_fip_enabled = cluster.labels.get(
"master_lb_floating_ip_enabled",
cluster_template.floating_ip_enabled
)
master_lb_fip_enabled = strutils.bool_from_string(lb_fip_enabled)
if cluster_template.floating_ip_enabled:
env_files.append(COMMON_ENV_PATH + 'enable_floating_ip.yaml')
if cluster_template.master_lb_enabled:
env_files.append(COMMON_ENV_PATH + 'enable_lb_floating_ip.yaml')
else:
env_files.append(COMMON_ENV_PATH + 'disable_floating_ip.yaml')
if cluster_template.master_lb_enabled:
env_files.append(COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml')
if cluster_template.master_lb_enabled and master_lb_fip_enabled:
env_files.append(COMMON_ENV_PATH + 'enable_lb_floating_ip.yaml')
else:
env_files.append(COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml')
def add_priv_net_env_file(env_files, cluster_template):

5
magnum/drivers/k8s_coreos_v1/templates/kubecluster.yaml

@ -515,7 +515,7 @@ resources:
private_network_name: private
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
@ -523,10 +523,9 @@ resources:
port: {get_param: kubernetes_port}
etcd_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_etcd.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
protocol: {get_param: loadbalancing_protocol}
port: 2379

5
magnum/drivers/k8s_fedora_atomic_v1/templates/kubecluster.yaml

@ -586,7 +586,7 @@ resources:
private_network_name: private
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
@ -594,10 +594,9 @@ resources:
port: {get_param: kubernetes_port}
etcd_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_etcd.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
protocol: {get_param: loadbalancing_protocol}
port: 2379

7
magnum/drivers/k8s_fedora_ironic_v1/templates/kubecluster.yaml

@ -11,7 +11,7 @@ parameters:
type: string
description: name of ssh key to be provisioned on our server
default: ""
external_network:
type: string
description: uuid/name of a network to use for floating ip addresses
@ -370,7 +370,7 @@ parameters:
resources:
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_param: fixed_subnet}
external_network: {get_param: external_network}
@ -378,10 +378,9 @@ resources:
port: {get_param: kubernetes_port}
etcd_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_etcd.yaml
properties:
fixed_subnet: {get_param: fixed_subnet}
external_network: {get_param: external_network}
protocol: {get_param: loadbalancing_protocol}
port: 2379

4
magnum/drivers/mesos_ubuntu_v1/templates/mesoscluster.yaml

@ -12,7 +12,7 @@ parameters:
type: string
description: name of ssh key to be provisioned on our server
default: ""
external_network:
type: string
description: uuid/name of a network to use for floating ip addresses
@ -242,7 +242,7 @@ resources:
external_network: {get_param: external_network}
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}

7
magnum/drivers/swarm_fedora_atomic_v1/templates/cluster.yaml

@ -17,7 +17,7 @@ parameters:
type: string
description: name of ssh key to be provisioned on our server
default: ""
external_network:
type: string
description: uuid/name of a network to use for floating ip addresses
@ -284,7 +284,7 @@ resources:
external_network: {get_param: external_network}
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
@ -292,10 +292,9 @@ resources:
port: {get_param: swarm_port}
etcd_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_etcd.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}
protocol: {get_param: loadbalancing_protocol}
port: 2379

2
magnum/drivers/swarm_fedora_atomic_v2/templates/swarmcluster.yaml

@ -221,7 +221,7 @@ resources:
external_network: {get_param: external_network}
api_lb:
type: ../../common/templates/lb.yaml
type: ../../common/templates/lb_api.yaml
properties:
fixed_subnet: {get_attr: [network, fixed_subnet]}
external_network: {get_param: external_network}

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

@ -304,6 +304,7 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml',
],
env_files)
@ -424,6 +425,7 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml'
],
env_files)
@ -532,6 +534,7 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml'
],
env_files)
@ -630,7 +633,9 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/no_etcd_volume.yaml',
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml'],
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml'
],
env_files)
@patch('requests.get')
@ -726,7 +731,9 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/no_etcd_volume.yaml',
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml'],
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml'
],
env_files)
@patch('requests.get')
@ -970,6 +977,7 @@ class TestClusterConductorWithK8s(base.TestCase):
'../../common/templates/environments/with_volume.yaml',
'../../common/templates/environments/no_master_lb.yaml',
'../../common/templates/environments/disable_floating_ip.yaml',
'../../common/templates/environments/disable_lb_floating_ip.yaml',
],
env_files)
reqget.assert_called_once_with('http://etcd/test?size=1', proxies={

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

@ -185,39 +185,107 @@ class TemplateDefinitionTestCase(base.TestCase):
def test_add_fip_env_lb_disabled_with_fp(self):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=True,
master_lb_enabled=False)
master_lb_enabled=False,
labels={})
mock_cluster = mock.MagicMock(labels={})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template)
self.assertEqual([cmn_tdef.COMMON_ENV_PATH +
'enable_floating_ip.yaml'], env_files)
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'enable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml'
],
env_files
)
def test_add_fip_env_lb_enabled_with_fp(self):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=True,
master_lb_enabled=True)
master_lb_enabled=True,
labels={})
mock_cluster = mock.MagicMock(labels={})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template)
self.assertEqual([cmn_tdef.COMMON_ENV_PATH +
'enable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH +
'enable_lb_floating_ip.yaml'], env_files)
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'enable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'enable_lb_floating_ip.yaml'
],
env_files
)
def test_add_fip_env_lb_disabled_without_fp(self):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=False,
master_lb_enabled=False)
master_lb_enabled=False,
labels={})
mock_cluster = mock.MagicMock(labels={})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template)
self.assertEqual([cmn_tdef.COMMON_ENV_PATH +
'disable_floating_ip.yaml'], env_files)
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'disable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml'
],
env_files
)
def test_add_fip_env_lb_enabled_without_fp(self):
mock_cluster_template = mock.MagicMock(floating_ip_enabled=False,
master_lb_enabled=True)
master_lb_enabled=True,
labels={})
mock_cluster = mock.MagicMock(labels={})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template)
self.assertEqual([cmn_tdef.COMMON_ENV_PATH +
'disable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH +
'disable_lb_floating_ip.yaml'], env_files)
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'disable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml'
],
env_files
)
def test_add_fip_env_lb_fip_enabled_without_fp(self):
mock_cluster_template = mock.MagicMock(
floating_ip_enabled=False,
master_lb_enabled=True,
labels={"master_lb_floating_ip_enabled": "true"}
)
mock_cluster = mock.MagicMock(
labels={"master_lb_floating_ip_enabled": "true"})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'disable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'enable_lb_floating_ip.yaml'
],
env_files
)
def test_add_fip_env_lb_enable_lbfip_disable(self):
mock_cluster_template = mock.MagicMock(
floating_ip_enabled=False,
master_lb_enabled=True,
labels={"master_lb_floating_ip_enabled": "false"}
)
mock_cluster = mock.MagicMock(
labels={"master_lb_floating_ip_enabled": "false"})
env_files = []
cmn_tdef.add_fip_env_file(env_files, mock_cluster_template,
mock_cluster)
self.assertEqual(
[
cmn_tdef.COMMON_ENV_PATH + 'disable_floating_ip.yaml',
cmn_tdef.COMMON_ENV_PATH + 'disable_lb_floating_ip.yaml'
],
env_files
)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
def test_base_get_scale_params(self, mock_driver):
@ -247,7 +315,6 @@ class BaseK8sTemplateDefinitionTestCase(base.TestCase):
private_ip_output_key='kube_masters_private',
cluster_attr='master_addresses',
):
definition = self.get_definition()
expected_address = expected_public_address = ['public']

10
releasenotes/notes/k8s-improve-floating-ip-enabled-84cd00224d6b7bc1.yaml

@ -0,0 +1,10 @@
upgrade:
- The etcd service for Kubernetes cluster is no longer allocated a floating
IP.
features:
- A new label named ``master_lb_floating_ip_enabled`` is introduced which
controls if Magnum allocates floating IP for the load balancer of master
nodes. This label only takes effect when the ``master_lb_enabled`` is set.
The default value is the same as ``floating_ip_enabled``. The
``floating_ip_enabled`` property now only controls if Magnum should
allocate the floating IPs for the master and worker nodes.
Loading…
Cancel
Save