Introduce kuryr-k8s
service
This commit introduces the `kuryr-k8s` service by adding the service binary and focusing on loading configuration options. The configuration options are inherited from kuryr-lib project (http://github.com/openstack/kuryr) and loaded at runtime, together with the project ones. These configuration options can be also generated using the `oslo-config-generator` utility by using: tox -e genconfig The service runs as any other OpenStack-based service: kuryr-k8s [--debug] [--config-file foo] ... Partial-Implements: blueprint kuryr-k8s-integration Change-Id: I7e52aef8fb2767dcc46317f2212f4285a17b11da Signed-off-by: Jaume Devesa <devvesa@gmail.com> Co-Authored-By: Taku Fukushima <f.tac.mac@gmail.com>
This commit is contained in:
parent
04a95048a4
commit
86e35666c4
1
.gitignore
vendored
1
.gitignore
vendored
@ -53,7 +53,6 @@ ChangeLog
|
||||
contrib/vagrant/.vagrant
|
||||
|
||||
# Configuration files
|
||||
etc/kuryr.conf
|
||||
etc/kuryr.conf.sample
|
||||
|
||||
# Ignore user specific local.conf settings for vagrant
|
||||
|
6
etc/README-config.txt
Normal file
6
etc/README-config.txt
Normal file
@ -0,0 +1,6 @@
|
||||
To generate the sample kuryr.conf file, run the following
|
||||
command from the top level of the kuryr directory:
|
||||
|
||||
tox -e genconfig
|
||||
|
||||
The sample file will be generated at etc/kuryr-k8s.conf.sample
|
5
etc/kuryr-k8s-config-generator.conf
Normal file
5
etc/kuryr-k8s-config-generator.conf
Normal file
@ -0,0 +1,5 @@
|
||||
[DEFAULT]
|
||||
output_file = etc/kuryr.conf.sample
|
||||
wrap_width = 79
|
||||
namespace = kuryr_kubernetes
|
||||
namespace = kuryr_lib
|
65
kuryr_kubernetes/config.py
Normal file
65
kuryr_kubernetes/config.py
Normal file
@ -0,0 +1,65 @@
|
||||
# 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.
|
||||
import os
|
||||
import sys
|
||||
|
||||
from kuryr.lib._i18n import _, _LI
|
||||
from kuryr.lib import config as lib_config
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from pbr import version as pbr_version
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
kuryr_k8s_opts = [
|
||||
cfg.StrOpt('pybasedir',
|
||||
help=_('Directory where Kuryr-kubernetes python module is '
|
||||
'installed.'),
|
||||
default=os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
'../../'))),
|
||||
]
|
||||
|
||||
k8s_opts = [
|
||||
cfg.StrOpt('api_root',
|
||||
help=_("The root URL of the Kubernetes API"),
|
||||
default=os.environ.get('K8S_API', 'http://localhost:8080')),
|
||||
]
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
CONF.register_opts(lib_config.core_opts)
|
||||
CONF.register_opts(lib_config.neutron_opts, group='neutron_client')
|
||||
CONF.register_opts(lib_config.keystone_opts, group='keystone_client')
|
||||
CONF.register_opts(lib_config.binding_opts, 'binding')
|
||||
|
||||
CONF.register_opts(kuryr_k8s_opts)
|
||||
CONF.register_opts(k8s_opts, group='kubernetes')
|
||||
logging.register_options(CONF)
|
||||
|
||||
|
||||
def init(args, **kwargs):
|
||||
version_k8s = pbr_version.VersionInfo('kuryr-kubernetes').version_string()
|
||||
CONF(args=args, project='kuryr-k8s', version=version_k8s, **kwargs)
|
||||
|
||||
|
||||
def setup_logging():
|
||||
|
||||
logging.setup(CONF, 'kuryr-kubernetes')
|
||||
logging.set_defaults(default_log_levels=logging.get_default_log_levels())
|
||||
version_k8s = pbr_version.VersionInfo('kuryr-kubernetes').version_string()
|
||||
LOG.info(_LI("Logging enabled!"))
|
||||
LOG.info(_LI("%(prog)s version %(version)s"),
|
||||
{'prog': sys.argv[0],
|
||||
'version': version_k8s})
|
39
kuryr_kubernetes/opts.py
Normal file
39
kuryr_kubernetes/opts.py
Normal file
@ -0,0 +1,39 @@
|
||||
# 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.
|
||||
import copy
|
||||
|
||||
from kuryr_kubernetes import config
|
||||
|
||||
_kuryr_k8s_opts = [
|
||||
('kubernetes', config.k8s_opts),
|
||||
('kuryr-kubernetes', config.kuryr_k8s_opts),
|
||||
]
|
||||
|
||||
|
||||
def list_kuryr_opts():
|
||||
"""Return a list of oslo_config options available in Kuryr service.
|
||||
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
|
||||
This function is also discoverable via the 'kuryr' entry point under
|
||||
the 'oslo_config.opts' namespace.
|
||||
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by Kuryr.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
|
||||
return [(k, copy.deepcopy(o)) for k, o in _kuryr_k8s_opts]
|
59
kuryr_kubernetes/server.py
Normal file
59
kuryr_kubernetes/server.py
Normal file
@ -0,0 +1,59 @@
|
||||
# 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.
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
from kuryr.lib._i18n import _LI
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import service
|
||||
|
||||
from kuryr_kubernetes import config
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class KuryrK8sService(service.Service):
|
||||
|
||||
def __init__(self):
|
||||
super(KuryrK8sService, self).__init__()
|
||||
|
||||
def start(self):
|
||||
# TODO(devvesa): Remove this line as soon as it does anything
|
||||
LOG.info(_LI("I am doing nothing"))
|
||||
try:
|
||||
while(True):
|
||||
time.sleep(5)
|
||||
# TODO(devvesa): Remove this line as soon as does anything
|
||||
LOG.info(_LI("Keep doing nothing"))
|
||||
finally:
|
||||
sys.exit(1)
|
||||
|
||||
def wait(self):
|
||||
"""Waits for K8sController to complete."""
|
||||
super(KuryrK8sService, self).wait()
|
||||
|
||||
def stop(self, graceful=False):
|
||||
"""Stops the event loop if it's not stopped already."""
|
||||
super(KuryrK8sService, self).stop(graceful)
|
||||
|
||||
|
||||
def start():
|
||||
config.init(sys.argv[1:])
|
||||
config.setup_logging()
|
||||
kuryrk8s_launcher = service.launch(config.CONF, KuryrK8sService())
|
||||
kuryrk8s_launcher.wait()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
start()
|
@ -2,16 +2,4 @@
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
pbr>=1.6 # Apache-2.0
|
||||
Babel>=2.3.4 # BSD
|
||||
Flask<1.0,>=0.10 # BSD
|
||||
jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT
|
||||
netaddr!=0.7.16,>=0.7.12 # BSD
|
||||
oslo.concurrency>=3.8.0 # Apache-2.0
|
||||
oslo.log>=1.14.0 # Apache-2.0
|
||||
oslo.serialization>=1.10.0 # Apache-2.0
|
||||
oslo.utils>=3.5.0 # Apache-2.0
|
||||
python-neutronclient>=4.2.0 # Apache-2.0
|
||||
pyroute2>=0.3.10 # Apache-2.0 (+ dual licensed GPL2)
|
||||
os-client-config>=1.13.1 # Apache-2.0
|
||||
neutron-lib>=0.1.0 # Apache-2.0
|
||||
-e git://github.com/openstack/kuryr.git@master#egg=kuryr_lib
|
||||
|
13
setup.cfg
13
setup.cfg
@ -13,15 +13,20 @@ classifier =
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Operating System :: POSIX :: Linux
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 2
|
||||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.3
|
||||
Programming Language :: Python :: 3.4
|
||||
|
||||
[entry_points]
|
||||
oslo.config.opts =
|
||||
kuryr_kubernetes = kuryr_kubernetes.opts:list_kuryr_opts
|
||||
kuryr_lib = kuryr.lib.opts:list_kuryr_opts
|
||||
|
||||
console_scripts =
|
||||
kuryr-k8s = kuryr_kubernetes.server:start
|
||||
|
||||
[files]
|
||||
packages =
|
||||
kuryr-kubernetes
|
||||
kuryr_kubernetes
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
2
tox.ini
2
tox.ini
@ -73,4 +73,4 @@ import_exceptions = neutron.i18n
|
||||
local-check-factory = neutron_lib.hacking.checks.factory
|
||||
|
||||
[testenv:genconfig]
|
||||
commands = oslo-config-generator --config-file=etc/kuryr-config-generator.conf
|
||||
commands = oslo-config-generator --config-file=etc/kuryr-k8s-config-generator.conf
|
||||
|
Loading…
x
Reference in New Issue
Block a user