From 5af49aa2fac601569faa38f42b46f988b8059a82 Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Fri, 27 Nov 2020 11:18:29 +0000 Subject: [PATCH] Add support for choosing Octavia provider Story: 2008805 Add support for: * choosing Octavia provider * setting octavia_lb_algorithm * disabling Octavia healthcheck Change-Id: I2d424fc2e2f8967e4b3007faedbc089f37126968 --- doc/source/user/index.rst | 17 +++++++++++ .../fragments/write-heat-params-master.sh | 3 ++ .../kubernetes/fragments/write-heat-params.sh | 3 ++ .../fragments/write-kube-os-config.sh | 4 ++- magnum/drivers/common/templates/lb_api.yaml | 21 ++++++++++++- magnum/drivers/common/templates/lb_etcd.yaml | 21 ++++++++++++- magnum/drivers/heat/k8s_template_def.py | 5 +++- .../templates/kubecluster.yaml | 30 +++++++++++++++++++ .../templates/kubemaster.yaml | 20 +++++++++++++ .../templates/kubeminion.yaml | 21 +++++++++++++ .../handlers/test_k8s_cluster_conductor.py | 22 ++++++++++++-- .../unit/drivers/test_template_definition.py | 13 ++++++++ .../notes/lb-algorithm-36a15eb21fd5c4b1.yaml | 5 ++++ .../octavia-provider-3984ee3bf381ced1.yaml | 5 ++++ 14 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/lb-algorithm-36a15eb21fd5c4b1.yaml create mode 100644 releasenotes/notes/octavia-provider-3984ee3bf381ced1.yaml diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst index b7a40708c1..60e119882f 100644 --- a/doc/source/user/index.rst +++ b/doc/source/user/index.rst @@ -502,6 +502,12 @@ the table are linked to more details elsewhere in the user guide. +---------------------------------------+--------------------+---------------+ | `fixed_subnet_cidr`_ | see below | "" | +---------------------------------------+--------------------+---------------+ +| `octavia_provider`_ | see below | amphora | ++---------------------------------------+--------------------+---------------+ +| `octavia_lb_algorithm`_ | see bellow | ROUND_ROBIN | ++---------------------------------------+--------------------+---------------+ +| `octavia_lb_healthcheck`_ | see bellow | true | ++---------------------------------------+--------------------+---------------+ .. _cluster: @@ -1635,6 +1641,17 @@ _`fixed_subnet_cidr` specified an existing fixed_subnet during cluster creation. Ussuri default: 10.0.0.0/24 +_`octavia_provider` + Octavia provider driver to be used for creating load balancers. + +_`octavia_lb_algorithm` + Octavia Octavia lb algorithm to use for LoadBalancer type service + Default: ROUND_ROBIN + +_`octavia_lb_healthcheck` + If true, enable Octavia load balancer healthcheck + Default: true + External load balancer for services ----------------------------------- diff --git a/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params-master.sh b/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params-master.sh index 4f723fd822..a50b184558 100644 --- a/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params-master.sh +++ b/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params-master.sh @@ -112,6 +112,9 @@ KUBEAPI_OPTIONS="$KUBEAPI_OPTIONS" KUBEPROXY_OPTIONS="$KUBEPROXY_OPTIONS" KUBESCHEDULER_OPTIONS="$KUBESCHEDULER_OPTIONS" OCTAVIA_ENABLED="$OCTAVIA_ENABLED" +OCTAVIA_PROVIDER="$OCTAVIA_PROVIDER" +OCTAVIA_LB_ALGORITHM="$OCTAVIA_LB_ALGORITHM" +OCTAVIA_LB_HEALTHCHECK="$OCTAVIA_LB_HEALTHCHECK" KUBE_SERVICE_ACCOUNT_KEY="$KUBE_SERVICE_ACCOUNT_KEY" KUBE_SERVICE_ACCOUNT_PRIVATE_KEY="$KUBE_SERVICE_ACCOUNT_PRIVATE_KEY" PROMETHEUS_TAG="$PROMETHEUS_TAG" diff --git a/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params.sh b/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params.sh index 3283fa60a5..dd849a7afe 100644 --- a/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params.sh +++ b/magnum/drivers/common/templates/kubernetes/fragments/write-heat-params.sh @@ -74,6 +74,9 @@ DNS_CLUSTER_DOMAIN="$DNS_CLUSTER_DOMAIN" KUBELET_OPTIONS="$KUBELET_OPTIONS" KUBEPROXY_OPTIONS="$KUBEPROXY_OPTIONS" OCTAVIA_ENABLED="$OCTAVIA_ENABLED" +OCTAVIA_PROVIDER="$OCTAVIA_PROVIDER" +OCTAVIA_LB_ALGORITHM=$OCTAVIA_LB_ALGORITHM +OCTAVIA_LB_HEALTHCHECK=$OCTAVIA_LB_HEALTHCHECK HEAT_CONTAINER_AGENT_TAG="$HEAT_CONTAINER_AGENT_TAG" AUTO_HEALING_ENABLED="$AUTO_HEALING_ENABLED" AUTO_HEALING_CONTROLLER="$AUTO_HEALING_CONTROLLER" diff --git a/magnum/drivers/common/templates/kubernetes/fragments/write-kube-os-config.sh b/magnum/drivers/common/templates/kubernetes/fragments/write-kube-os-config.sh index 274e1adb22..71874d24a3 100644 --- a/magnum/drivers/common/templates/kubernetes/fragments/write-kube-os-config.sh +++ b/magnum/drivers/common/templates/kubernetes/fragments/write-kube-os-config.sh @@ -20,7 +20,9 @@ ca-file=/etc/kubernetes/ca-bundle.crt use-octavia=$OCTAVIA_ENABLED subnet-id=$CLUSTER_SUBNET floating-network-id=$EXTERNAL_NETWORK_ID -create-monitor=yes +lb-provider=$OCTAVIA_PROVIDER +lb-method=$OCTAVIA_LB_ALGORITHM +create-monitor=$OCTAVIA_LB_HEALTHCHECK monitor-delay=1m monitor-timeout=30s monitor-max-retries=3 diff --git a/magnum/drivers/common/templates/lb_api.yaml b/magnum/drivers/common/templates/lb_api.yaml index 2a09eb6a6f..2e9c5b9d4a 100644 --- a/magnum/drivers/common/templates/lb_api.yaml +++ b/magnum/drivers/common/templates/lb_api.yaml @@ -10,6 +10,11 @@ conditions: - get_param: allowed_cidrs - [] + octavia_lb_healthcheck_enabled: + equals: + - get_param: octavia_lb_healthcheck + - [] + parameters: fixed_subnet: @@ -31,10 +36,23 @@ parameters: type: comma_delimited_list description: The allowed CIDR list for master load balancer + octavia_provider: + type: string + description: Octavia provider to use for load balancer + + octavia_lb_algorithm: + type: string + description: Octavia load balancer algorithm to use + + octavia_lb_healthcheck: + type: boolean + description: Octavia load balancer healthcheck + resources: loadbalancer: type: Magnum::Optional::Neutron::LBaaS::LoadBalancer properties: + provider: {get_param: octavia_provider} vip_subnet: {get_param: fixed_subnet} listener: @@ -57,11 +75,12 @@ resources: pool: type: Magnum::Optional::Neutron::LBaaS::Pool properties: - lb_algorithm: ROUND_ROBIN + lb_algorithm: {get_param: octavia_lb_algorithm} listener: {if: ["allowed_cidrs_enabled", {get_resource: listener_with_allowed_cidrs}, {get_resource: listener}]} protocol: {get_param: protocol} monitor: + condition: octavia_lb_healthcheck_enabled type: Magnum::Optional::Neutron::LBaaS::HealthMonitor properties: type: TCP diff --git a/magnum/drivers/common/templates/lb_etcd.yaml b/magnum/drivers/common/templates/lb_etcd.yaml index 39b8733de5..85b17cc80b 100644 --- a/magnum/drivers/common/templates/lb_etcd.yaml +++ b/magnum/drivers/common/templates/lb_etcd.yaml @@ -11,6 +11,11 @@ conditions: - get_param: allowed_cidrs - [] + octavia_lb_healthcheck_enabled: + equals: + - get_param: octavia_lb_healthcheck + - [] + parameters: fixed_subnet: @@ -29,10 +34,23 @@ parameters: type: comma_delimited_list description: The allowed CIDR list for master load balancer + octavia_provider: + type: string + description: Octavia provider to use for load balancer + + octavia_lb_algorithm: + type: string + description: Octavia load balancer algorithm to use + + octavia_lb_healthcheck: + type: boolean + description: Octavia load balancer healthcheck + resources: loadbalancer: type: Magnum::Optional::Neutron::LBaaS::LoadBalancer properties: + provider: {get_param: octavia_provider} vip_subnet: {get_param: fixed_subnet} listener: @@ -55,11 +73,12 @@ resources: pool: type: Magnum::Optional::Neutron::LBaaS::Pool properties: - lb_algorithm: ROUND_ROBIN + lb_algorithm: {get_param: octavia_lb_algorithm} listener: {if: ["allowed_cidrs_enabled", {get_resource: listener_with_allowed_cidrs}, {get_resource: listener}]} protocol: {get_param: protocol} monitor: + condition: octavia_lb_healthcheck_enabled type: Magnum::Optional::Neutron::LBaaS::HealthMonitor properties: type: TCP diff --git a/magnum/drivers/heat/k8s_template_def.py b/magnum/drivers/heat/k8s_template_def.py index 2549a0a3b7..43e89bb3be 100644 --- a/magnum/drivers/heat/k8s_template_def.py +++ b/magnum/drivers/heat/k8s_template_def.py @@ -257,7 +257,10 @@ class K8sTemplateDefinition(template_def.BaseTemplateDefinition): 'kubecontroller_options', 'kubescheduler_options', 'influx_grafana_dashboard_enabled', - 'master_lb_allowed_cidrs'] + 'master_lb_allowed_cidrs', + 'octavia_provider', + 'octavia_lb_algorithm', + 'octavia_lb_healthcheck'] labels = self._get_relevant_labels(cluster, kwargs) diff --git a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml index 3272a3dd4b..35ca781d42 100644 --- a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml +++ b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubecluster.yaml @@ -660,6 +660,24 @@ parameters: whether or not to use Octavia for LoadBalancer type service. default: False + octavia_provider: + type: string + default: amphora + description: > + Octavia provider driver to use for LoadBalancer type service. + + octavia_lb_algorithm: + type: string + default: ROUND_ROBIN + description: > + Octavia lb algorithm to use for LoadBalancer type service + + octavia_lb_healthcheck: + type: boolean + description: > + if true, enable Octavia load balancer healthcheck + default: true + kube_service_account_key: type: string hidden: true @@ -1021,6 +1039,9 @@ resources: protocol: {get_param: loadbalancing_protocol} port: {get_param: kubernetes_port} allowed_cidrs: {get_param: master_lb_allowed_cidrs} + octavia_provider: {get_param: octavia_provider} + octavia_lb_algorithm: {get_param: octavia_lb_algorithm} + octavia_lb_healthcheck: {get_param: octavia_lb_healthcheck} etcd_lb: condition: create_cluster_resources @@ -1030,6 +1051,9 @@ resources: protocol: {get_param: loadbalancing_protocol} port: 2379 allowed_cidrs: {get_param: master_lb_allowed_cidrs} + octavia_provider: {get_param: octavia_provider} + octavia_lb_algorithm: {get_param: octavia_lb_algorithm} + octavia_lb_healthcheck: {get_param: octavia_lb_healthcheck} ###################################################################### # @@ -1317,6 +1341,9 @@ resources: kubecontroller_options: {get_param: kubecontroller_options} kubescheduler_options: {get_param: kubescheduler_options} octavia_enabled: {get_param: octavia_enabled} + octavia_provider: {get_param: octavia_provider} + octavia_lb_algorithm: {get_param: octavia_lb_algorithm} + octavia_lb_healthcheck: {get_param: octavia_lb_healthcheck} kube_service_account_key: {get_param: kube_service_account_key} kube_service_account_private_key: {get_param: kube_service_account_private_key} prometheus_tag: {get_param: prometheus_tag} @@ -1538,6 +1565,9 @@ resources: kubelet_options: {get_param: kubelet_options} kubeproxy_options: {get_param: kubeproxy_options} octavia_enabled: {get_param: octavia_enabled} + octavia_provider: {get_param: octavia_provider} + octavia_lb_algorithm: {get_param: octavia_lb_algorithm} + octavia_lb_healthcheck: {get_param: octavia_lb_healthcheck} heat_container_agent_tag: {get_param: heat_container_agent_tag} auto_healing_enabled: {get_param: auto_healing_enabled} npd_enabled: {get_param: npd_enabled} diff --git a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubemaster.yaml b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubemaster.yaml index bcecb4f4e4..a038f144d0 100644 --- a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubemaster.yaml +++ b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubemaster.yaml @@ -434,6 +434,23 @@ parameters: whether or not to use Octavia for LoadBalancer type service. default: False + octavia_provider: + type: string + description: > + Octavia provider driver to use for LoadBalancer type service. + + octavia_lb_algorithm: + type: string + default: ROUND_ROBIN + description: > + Octavia lb algorithm to use for LoadBalancer type service. + + octavia_lb_healthcheck: + type: boolean + default: True + description: > + Octavia lb healthcheck. + kube_service_account_key: type: string hidden: true @@ -849,6 +866,9 @@ resources: "$KUBEPROXY_OPTIONS": {get_param: kubeproxy_options} "$KUBESCHEDULER_OPTIONS": {get_param: kubescheduler_options} "$OCTAVIA_ENABLED": {get_param: octavia_enabled} + "$OCTAVIA_PROVIDER": {get_param: octavia_provider} + "$OCTAVIA_LB_ALGORITHM": {get_param: octavia_lb_algorithm} + "$OCTAVIA_LB_HEALTHCHECK": {get_param: octavia_lb_healthcheck} "$KUBE_SERVICE_ACCOUNT_KEY": {get_param: kube_service_account_key} "$KUBE_SERVICE_ACCOUNT_PRIVATE_KEY": {get_param: kube_service_account_private_key} "$PROMETHEUS_TAG": {get_param: prometheus_tag} diff --git a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml index 98b10db093..3666b2cebf 100644 --- a/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml +++ b/magnum/drivers/k8s_fedora_coreos_v1/templates/kubeminion.yaml @@ -294,6 +294,24 @@ parameters: whether or not to use Octavia for LoadBalancer type service. default: False + octavia_provider: + type: string + description: > + Octavia provider driver to use for LoadBalancer type service. + default: False + + octavia_lb_algorithm: + type: string + default: ROUND_ROBIN + description: > + Octavia lb algorithm to use for LoadBalancer type service. + + octavia_lb_healthcheck: + type: boolean + default: True + description: > + Octavia lb healthcheck. + cloud_provider_enabled: type: boolean description: Enable or disable the openstack kubernetes cloud provider @@ -482,6 +500,9 @@ resources: $KUBELET_OPTIONS: {get_param: kubelet_options} $KUBEPROXY_OPTIONS: {get_param: kubeproxy_options} $OCTAVIA_ENABLED: {get_param: octavia_enabled} + $OCTAVIA_PROVIDER: {get_param: octavia_provider} + $OCTAVIA_LB_ALGORITHM: {get_param: octavia_lb_algorithm} + $OCTAVIA_LB_HEALTHCHECK: {get_param: octavia_lb_healthcheck} $HEAT_CONTAINER_AGENT_TAG: {get_param: heat_container_agent_tag} $AUTO_HEALING_ENABLED: {get_param: auto_healing_enabled} $AUTO_HEALING_CONTROLLER: {get_param: auto_healing_controller} diff --git a/magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py b/magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py index 4c17039b1c..0850821d9f 100644 --- a/magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py +++ b/magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py @@ -382,6 +382,9 @@ class TestClusterConductorWithK8s(base.TestCase): 'post_install_manifest_url': '', 'master_lb_allowed_cidrs': None, 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } if missing_attr is not None: @@ -538,7 +541,10 @@ class TestClusterConductorWithK8s(base.TestCase): 'worker_nodegroup_name': 'worker_ng', 'post_install_manifest_url': '', 'master_lb_allowed_cidrs': None, - 'fixed_subnet_cidr': self.fixed_subnet_cidr + 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } self.assertEqual(expected, definition) @@ -676,7 +682,10 @@ class TestClusterConductorWithK8s(base.TestCase): 'worker_nodegroup_name': 'worker_ng', 'post_install_manifest_url': '', 'master_lb_allowed_cidrs': None, - 'fixed_subnet_cidr': self.fixed_subnet_cidr + 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } self.assertEqual(expected, definition) self.assertEqual( @@ -794,6 +803,9 @@ class TestClusterConductorWithK8s(base.TestCase): 'worker_nodegroup_name': 'worker_ng', 'master_lb_allowed_cidrs': None, 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } self.assertEqual(expected, definition) self.assertEqual( @@ -909,6 +921,9 @@ class TestClusterConductorWithK8s(base.TestCase): 'worker_nodegroup_name': 'worker_ng', 'master_lb_allowed_cidrs': None, 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } self.assertEqual(expected, definition) self.assertEqual( @@ -1160,6 +1175,9 @@ class TestClusterConductorWithK8s(base.TestCase): 'post_install_manifest_url': '', 'master_lb_allowed_cidrs': None, 'fixed_subnet_cidr': self.fixed_subnet_cidr, + 'octavia_provider': None, + 'octavia_lb_algorithm': None, + 'octavia_lb_healthcheck': None, } self.assertEqual(expected, definition) self.assertEqual( diff --git a/magnum/tests/unit/drivers/test_template_definition.py b/magnum/tests/unit/drivers/test_template_definition.py index 570e196176..acfc0d75f3 100644 --- a/magnum/tests/unit/drivers/test_template_definition.py +++ b/magnum/tests/unit/drivers/test_template_definition.py @@ -622,6 +622,9 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase): metrics_scraper_tag = mock_cluster.labels.get('metrics_scraper_tag') master_lb_allowed_cidrs = mock_cluster.labels.get( 'master_lb_allowed_cidrs') + octavia_provider = mock_cluster.labels.get('octavia_provider') + octavia_lb_algorithm = mock_cluster.labels.get('octavia_lb_algorithm') + octavia_lb_healthcheck = mock_cluster.labels.get('octavia_lb_healthcheck') k8s_def = k8sa_tdef.AtomicK8sTemplateDefinition() @@ -746,6 +749,9 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase): 'metrics_scraper_tag': metrics_scraper_tag, 'master_lb_allowed_cidrs': master_lb_allowed_cidrs, 'fixed_subnet_cidr': '20.200.0.0/16', + 'octavia_provider': octavia_provider, + 'octavia_lb_algorithm': octavia_lb_algorithm, + 'octavia_lb_healthcheck': octavia_lb_healthcheck, }} mock_get_params.assert_called_once_with(mock_context, mock_cluster_template, @@ -1178,6 +1184,10 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase): master_lb_allowed_cidrs = mock_cluster.labels.get( 'master_lb_allowed_cidrs') + octavia_provider = mock_cluster.labels.get('octavia_provider') + octavia_lb_algorithm = mock_cluster.labels.get('octavia_lb_algorithm') + octavia_lb_healthcheck = mock_cluster.labels.get('octavia_lb_healthcheck') + k8s_def = k8sa_tdef.AtomicK8sTemplateDefinition() k8s_def.get_params(mock_context, mock_cluster_template, mock_cluster) @@ -1303,6 +1313,9 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase): 'metrics_scraper_tag': metrics_scraper_tag, 'master_lb_allowed_cidrs': master_lb_allowed_cidrs, 'fixed_subnet_cidr': '20.200.0.0/16', + 'octavia_provider': octavia_provider, + 'octavia_lb_algorithm': octavia_lb_algorithm, + 'octavia_lb_healthcheck': octavia_lb_healthcheck, }} mock_get_params.assert_called_once_with(mock_context, mock_cluster_template, diff --git a/releasenotes/notes/lb-algorithm-36a15eb21fd5c4b1.yaml b/releasenotes/notes/lb-algorithm-36a15eb21fd5c4b1.yaml new file mode 100644 index 0000000000..252da82ace --- /dev/null +++ b/releasenotes/notes/lb-algorithm-36a15eb21fd5c4b1.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added support for choosing Octavia LB algorithm by using + ``octavia_lb_algorithm`` tag. diff --git a/releasenotes/notes/octavia-provider-3984ee3bf381ced1.yaml b/releasenotes/notes/octavia-provider-3984ee3bf381ced1.yaml new file mode 100644 index 0000000000..5df4aa6029 --- /dev/null +++ b/releasenotes/notes/octavia-provider-3984ee3bf381ced1.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added support for choosing Octavia provider driver by using + ``octavia_provider`` tag.