From bcc851aacf31594ca01e08c4c664008ee52557d7 Mon Sep 17 00:00:00 2001 From: Luis Tomas Bolivar Date: Tue, 14 Nov 2017 17:02:23 +0000 Subject: [PATCH] Add oslo_cache to default_subnet driver This patch adds oslo_cache to the default subnet driver to avoid unneed calls to neutron when creating pods (or when getting subnet information) Change-Id: I93b6bed424757e4138ba656251ae5da46b857da1 --- kuryr_kubernetes/config.py | 10 +++++++++ .../controller/drivers/default_subnet.py | 20 ++++++++++++++++- kuryr_kubernetes/opts.py | 3 +++ .../notes/oslo-caching-b11881cfb9dc306c.yaml | 22 +++++++++++++++++++ requirements.txt | 1 + 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/oslo-caching-b11881cfb9dc306c.yaml diff --git a/kuryr_kubernetes/config.py b/kuryr_kubernetes/config.py index e15d05320..bc18d546f 100644 --- a/kuryr_kubernetes/config.py +++ b/kuryr_kubernetes/config.py @@ -148,6 +148,15 @@ octavia_defaults = [ default='L3'), ] +cache_defaults = [ + cfg.BoolOpt('enabled', + help=_("Enable caching."), + default=True), + cfg.StrOpt('backend', + help=_("Select backend cache option."), + default="dogpile.cache.memory"), +] + CONF = cfg.CONF CONF.register_opts(kuryr_k8s_opts) @@ -155,6 +164,7 @@ CONF.register_opts(daemon_opts, group='cni_daemon') CONF.register_opts(k8s_opts, group='kubernetes') CONF.register_opts(neutron_defaults, group='neutron_defaults') CONF.register_opts(octavia_defaults, group='octavia_defaults') +CONF.register_opts(cache_defaults, group='cache_defaults') CONF.register_opts(lib_config.core_opts) CONF.register_opts(lib_config.binding_opts, 'binding') diff --git a/kuryr_kubernetes/controller/drivers/default_subnet.py b/kuryr_kubernetes/controller/drivers/default_subnet.py index 13d875f32..5c4643774 100644 --- a/kuryr_kubernetes/controller/drivers/default_subnet.py +++ b/kuryr_kubernetes/controller/drivers/default_subnet.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_cache import core as cache from oslo_config import cfg from kuryr_kubernetes import clients @@ -21,8 +22,25 @@ from kuryr_kubernetes.controller.drivers import base from kuryr_kubernetes import os_vif_util +CONF = cfg.CONF + +subnet_caching_opts = [ + cfg.BoolOpt('caching', default=True), + cfg.IntOpt('cache_time', default=3600), +] + +CONF.register_opts(subnet_caching_opts, "subnet_caching") + +cache.configure(CONF) +subnet_cache_region = cache.create_region() +MEMOIZE = cache.get_memoization_decorator( + CONF, subnet_cache_region, "subnet_caching") + +cache.configure_cache_region(CONF, subnet_cache_region) + + +@MEMOIZE def _get_subnet(subnet_id): - # TODO(ivc): add caching (e.g. oslo.cache with dict backend) neutron = clients.get_neutron_client() n_subnet = neutron.show_subnet(subnet_id).get('subnet') diff --git a/kuryr_kubernetes/opts.py b/kuryr_kubernetes/opts.py index 2d5d89fff..01cfd48f0 100644 --- a/kuryr_kubernetes/opts.py +++ b/kuryr_kubernetes/opts.py @@ -15,6 +15,7 @@ from oslo_log import _options from kuryr.lib import opts as lib_opts from kuryr_kubernetes import config +from kuryr_kubernetes.controller.drivers import default_subnet from kuryr_kubernetes.controller.drivers import nested_vif from kuryr_kubernetes.controller.drivers import vif_pool from kuryr_kubernetes.controller.managers import pool @@ -26,6 +27,8 @@ _kuryr_k8s_opts = [ ('pod_vif_nested', nested_vif.nested_vif_driver_opts), ('vif_pool', vif_pool.vif_pool_driver_opts), ('octavia_defaults', config.octavia_defaults), + ('cache_defaults', config.cache_defaults), + ('subnet_caching', default_subnet.subnet_caching_opts), ('pool_manager', pool.pool_manager_opts), ('cni_daemon', config.daemon_opts), ] diff --git a/releasenotes/notes/oslo-caching-b11881cfb9dc306c.yaml b/releasenotes/notes/oslo-caching-b11881cfb9dc306c.yaml new file mode 100644 index 000000000..8bc6f1e0e --- /dev/null +++ b/releasenotes/notes/oslo-caching-b11881cfb9dc306c.yaml @@ -0,0 +1,22 @@ +--- +features: + - | + oslo.cache support has been added to the default_subnet driver. This + allows to skip unnecessary calls to neutron to retrieve network and + subnet information that can be cached and retrieved faster. It includes + the generic oslo caching options to enable/disable it as well as to + specify the backend to use (dogpile.cache.memory by default). In addition + it includes the specific options ofr the subnet driver, to enable/disable + it just for this driver, as well as to specify the cache time. To change + default configurations, the next can be modified at kuryr.conf + + .. code-block:: ini + + [cache] + enable=True + backend=dogpile.cache.memory + + [subnet_caching] + caching=True + cache_time=3600 + diff --git a/requirements.txt b/requirements.txt index 81e3c43aa..a5fd65079 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ kuryr-lib>=0.5.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0 requests>=2.14.2 # Apache-2.0 eventlet!=0.18.3,!=0.20.1,<0.21.0,>=0.18.2 # MIT +oslo.cache>=1.26.0 # Apache-2.0 oslo.config>=4.6.0 # Apache-2.0 oslo.log>=3.30.0 # Apache-2.0 oslo.reports>=1.18.0 # Apache-2.0