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
This commit is contained in:
Luis Tomas Bolivar 2017-11-14 17:02:23 +00:00
parent 9709abde08
commit bcc851aacf
5 changed files with 55 additions and 1 deletions

View File

@ -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')

View File

@ -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')

View File

@ -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),
]

View File

@ -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

View File

@ -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